2
以下代碼取自角度源代碼di.ts
。以下打字稿代碼的作用是什麼?
export interface AttributeDecorator {
(name: string): any;
new (name: string): Attribute;
}
我明白這是一個接口。但new (name: string): Attribute
正在做什麼,爲什麼有兩種類型的名稱,string and any
。
上述代碼之後是
export interface Attribute { attributeName?: string; }
export const Attribute: AttributeDecorator = makeParamDecorator('Attribute', (attributeName?: string) => ({attributeName}));
如果他們使用的任何屬性,而不是它是如何處理的?像'new(name:string):any;' –
@RameshRajendran'@ Attribute'是[參數裝飾器](https://www.typescriptlang.org/docs/handbook/decorators.html#parameter-decorators),它被使用作爲'構造函數(@Attribute(...)foo)'。我猜'any'是指這個語句,*參數裝飾器的返回值被忽略*。當用'new'調用時,裝飾器返回Attribute的一個實例,如接口所說。 – estus