export interface IBaseFormConfig {
hints?: string | (Map<string, any>): string;
validators?: any | (Map<string, any>): any;
}
这不起作用。这是一个装饰。因此开发人员可以装饰一个属性,如:
@IBaseFormConfig({
hints: 'This is the hint'
})
// or
@IBaseFormConfig({
hints: () => {
// Developers can resolve its hints dynamically with services.
return 'This is the hint';
}
})
如何正确编写此接口属性的类型定义?
答案 0 :(得分:2)
TypeScript中的字符串类型或函数回调?
简单:
export interface IBaseFormConfig {
hints?: string | { (arg: Map<string, any>): string };
}
它被称为可调用签名:https://basarat.gitbooks.io/typescript/content/docs/types/callable.html