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 –