![](/img/trans.png)
[英]Why does Typescript not like it when I use a simple object for an interface that has all optional props?
[英]when I use typescript compiler api, I found that interface ClassDeclaration contain optional property "name"
当我使用 typescript 编译器 api 时,我发现 interface ClassDeclaration
contain optional property name
。 如何获得没有名称的ClassDeclaration
节点?
我还发现接口InterfaceDeclaration
包含一个必需的属性name
。
为什么不同?
作为默认导出导出时,class 声明可能不包含名称。
export default class {
method() {
}
}
https://ts-ast-viewer.com/#code/KYDwDg9gTgLgBAE2AMwIYFcA28DGnUDOBcA3gFByVwC2wMAFhAgBQCUpFVAvmV0A
对于接口来说,这是不可能的,它会引发语法错误。
https://ts-ast-viewer.com/#code/KYDwDg9gTgLgBAE2AMwIYFcA28CWA7GYKNAY2DgG8AoAXyA
我不确定他们为什么这样决定,但不必担心名字可能不存在确实让事情变得更容易。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.