【发布时间】:2014-08-11 22:17:17
【问题描述】:
为了帮助this person,我正在删除Ampersand.js 库的打字稿定义。给定以下打字稿代码,为什么编译器会输出 Invalid 'new' experession 错误?
[Here's a link to run the code using the typescript playground.]
declare module ampersand {
interface AmpersandState {
// todo...
}
interface AmpersandCollection {
// todo...
}
interface ModelExtendOptions {
parse?: boolean;
parent?: AmpersandState;
collection?: AmpersandCollection;
}
interface ModelSaveOptions {
patch?: boolean;
}
class AmpersandModel<T> {
constructor(attrs: T, options?: ModelExtendOptions);
save: (attrs?: T, options?: ModelSaveOptions) => void;
// todo: fetch, destroy, sync, etc...
}
interface ExtendOptions {
props?: {};
session?: {};
derived?: {};
}
interface AmpersandModelStatic {
extend: <T>(options: ExtendOptions) => AmpersandModel<T>;
}
}
declare var AmpersandModel: ampersand.AmpersandModelStatic;
interface PersonProps {
firstName: string;
lastName: string;
}
var Person = AmpersandModel.extend<PersonProps>({ props: { firstName: 'string', lastName: 'string' } });
var me = new Person({ firstName: 'Phil', lastName: 'Roberts' });
“新”表达式无效。
【问题讨论】:
标签: typescript ampersand