我最近開始學習打字稿和角度然后,我遇到了這樣的短代碼 interface transform extends Function{ (param:string):string; }
所以我想知道,transform介面從介面繼承了什么樣的方法或回傳型別Function?同樣,如果我決定有一個回傳transform如下的方法:coordinate ():transform { },坐標回傳的預期型別是string什么?
uj5u.com熱心網友回復:
extends Function添加Function諸如call applyetc... 之類的方法以及Function行為,但它是多余的,因為您在介面中有一個函式定義:
interface ExtendedFunction extends Function { }
declare const extendedFunction: ExtendedFunction;
extendedFunction.apply // Works
extendedFunction('bla', 1, true); // Works
interface Transform {
(param: string): string;
}
declare const transform: Transform;
transform.apply // Works
transform('bla', 1, true) // Fails
transform('bla') // Works
TypeScript 游樂場
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/405307.html
標籤:
