【发布时间】:2022-11-15 22:40:28
【问题描述】:
所以我正在阅读this 文档,我真的很困惑这在 JavaScript 中是如何实现的。
type DescribableFunction = {
description: string;
(a: any): boolean;
};
function doSomething(fn: DescribableFunction) {
console.log(fn.description + " returned " + fn(6));
};
doSomething((()=>false)); // Argument of type '() => false' is not assignable to parameter of type 'DescribableFunction'. Property 'description' is missing in type '() => false' but required in type 'DescribableFunction'.
doSomething({description: 'test'}); // fn is not a function.
正如您在上面看到的,参数fn 怎么可能同时是对象和函数..?
【问题讨论】:
标签: typescript