其他分享
首页 > 其他分享> > [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]

 

标签:nestable,Typescript,infinitely,Recursion,NestedNumbers,221,type,Type,types
来源: https://www.cnblogs.com/Answer1215/p/16526008.html