typescript - 关于'Hybrid Types',为什么使用':interface name'会报错
问题描述
新手问题,为什么我不能使用第二种方法?
interface Counter {
(start: number): string;
interval: number;
reset(): void;
}
function getCounter(): Counter {
1. let counter = <Counter>function (start: number) { return '123' };
2. let counter: Counter = function (start: number) { return '123' };
counter.interval = 123;
counter.reset = function () { };
return counter;
}
第二种方法会提示'Type '(start: number) => string' is missing the following properties from type 'Counter': interval, reset'。它们之间有什么区别?
解决方案
推荐阅读
- azure - 检查应用服务从 Azure 容器存储库中提取映像的次数
- c++ - 关于c++函数中指针赋值的一个简单问题
- google-apps-script - 如何最好在不创建市场插件的情况下在域外共享谷歌网络应用程序
- sql - 嵌套分组查询的正确语法是什么?
- javascript - 使用 json 数据创建 html 表
- iis - IIS 和按目录压缩
- azure - 如何在 azure devops YAML 管道中将单个代理用于多个作业/阶段
- python - 点击后tkinter按钮不会释放
- angular - 带有 Tailwind CSS 的 Angular 9:数据路径“”不应具有其他属性(customWebpackConfig)
- python - 将 csv 文件上传到 Azure 失败,写入操作不完整