我正在尝试使用可选对象值创建类型定义。例如:
declare class SomeClass {
street:string;
name:string;
whatever:number;
}
declare class Person {
firstName:string;
lastName:string;
againWhatever:number;
}
declare class SomeClass extends SomeBase {
//with the added irrelevant code this comment is needed
// person can either be a person OR UNDEFINED
// person is optional but declare class does not allow
// specifying optional members
person? : Person
}
var s:SomeClass ={
street:""
,name:""
,whatever:22
};
[更新]
没有编译错误,但Visual Studio代码在类型定义中的?
下面放了一个红线。这必须是1.5.3的问题,更新到1.6.0打破了很多,所以我得到了“旧”版本,我使用的是typescript 2.0.3(节点)。尝试使用1.6.1并解决了typedef解析(1.5.3)和导入破解(1.6.0)的问题
可悲的是; Visual Studio 2013引发构建错误:A class member cannot be declared optional
阻止项目发布。
尝试获取Visual Studio 2013的最新版TypeScript,但它是我已经使用的版本。检查路径环境变量,并指向C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.8\
。猜猜我必须等待更新才能继续使用这些工具: - )