C/C++教程

[Typescript] Recursion Type

本文主要是介绍[Typescript] Recursion Type,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

Recursive types, are self-referential, and are often used to describe infinitely nestable types. For example, consider infinitely nestable arrays of numbers

[3, 4, [5, 6, [7], 59], 221]

You may read or see things that indicate you must use a combination of interface and type for recursive types. As of TypeScript 3.7 this is now much easier, and works with either type aliases or interfaces.

type NestedNumbers = number | NestedNumbers[]
 
const val: NestedNumbers = [3, 4, [5, 6, [7], 59], 221]

 

这篇关于[Typescript] Recursion Type的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!