1
我想在课堂上声明一个数字作为可选项,使用'?'运营商。Typescript'optional'(nullable)'?'语法不起作用(部分)
export class DummyClass {
dummyId?: number;
}
因为'; is expected. Unexpected token'
错误,Visual Studio不让我编译。然而,当我例如声明一个函数或接口,它的工作没有问题:
void(sup?: number) {} // nothing to complain here
是否有一些规则呢?或者Intellisense有问题?
TypeScript没有'可空'的概念。请参阅http://stackoverflow.com/questions/17220114/how-to-declare-a-type-as-nullable-in-typescript –