[英]How to define a tree type in TypeScript?
我写了像这样的树,如下所示:
type ReactNode = ReactChild | Array<ReactNode>
但是编辑告诉我
TS2456:类型别名“ ReactNode”循环引用自身。
如何解决此错误?
类型别名的递归存在问题,如本问题所述 :
类型别名与接口不同。 接口被命名为类型,类型别名只是别名。 在内部以及对它们的区别对待时,编译器会积极地将类型别名平化为其声明。
这里有更长的讨论: 允许递归泛型别名 。
就您而言,您可以执行以下操作:
interface ReactNodeArray extends Array<ReactNode> {} type ReactNode = ReactChild | ReactNodeArray;
[英]How to define array type in typescript?
[英]how to define the type of an observer in typescript
[英]How to define a new type in TypeScript
[英]How to define this typescript interface type
[英]How to define a type for a template in TypeScript?
[英]How to define `type` for `Electron` in typescript?
[英]How to define an opaque type in TypeScript?
[英]How to define type of interface in typescript?
[英]How to define static class type for a variable in TypeScript?
[英]In typescript, how to define type of async function
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.