![](/img/trans.png)
[英]How to describe object properties parameters for a function in typescript TSDoc?
[英]How to describe something callable with properties in TypeScript? And how to call the below function?
type DescribableFunction = {
description: string;
(someArg: number): boolean;
};
function doSomething(fn: DescribableFunction) {
console.log(fn.description + " returned " + fn(6));
}
console.log(doSomething({description="how are you", (9)=>return true;})) //error
我試圖用一些 arguments 調用上面的 function 但我收到如下錯誤
“此表達式不可調用。類型‘{描述:字符串;}’沒有調用簽名。(2349)(屬性)描述:任何”
我怎么稱呼這個 function?
您需要為 function 字段命名,以便稍后引用。 在將 object 作為參數傳遞時,您也有一些語法錯誤:
type DescribableFunction = {
description: string;
call: (someArg: number) => boolean;
};
function doSomething(fn: DescribableFunction) {
console.log(fn.description + " returned " + fn.call(6));
}
console.log(doSomething({description: "how are you", call: (x: number) => true }))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.