node.js - TypeScript:在此示例中预期类型错误。而没有得到他们。我错过了什么吗?还是只是丢了??:)
问题描述
对 TypeScript 来说不是那么新,但也许足够新?我在这里很困惑..我期待一些编译器错误并且没有得到它们。我错过了什么吗?
(更好/可运行的示例在 TS Playground:Playground Link上)
type Context<T> = {
data:any,
};
type EventNames = "beforeSave" | "afterSave" | "beforeDelete" | "afterDelete";
type EventHandler<T> = (context:Context<T>, next:()=>{})=>Promise<any>;
type EntityModel<T> = {
observe:(eventName:EventNames, handler:EventHandler<T>)=>void;
}
type OnlineShoppingCart ={
[key: string]:any
}
const model:EntityModel<OnlineShoppingCart> = {
observe: (eventName:EventNames)=> {
// why am I not getting a compiler error here?
// observe is not properly implemented!
}
};
model.observe('beforeSave', async ()=>{
// why am I not getting a compiler error here?
//This arrow function does not properly implement EventHandler<T>
})
解决方案
推荐阅读
- python - bot 没有运行 bs4 discord.py
- merge - Javascript:重构对象数组而不覆盖键
- php - 从服务器传输到服务器时加密的 Sql 数据是否安全
- javascript - 如何在 Polymer/lit-element 项目中使用箭头功能
- keras - 图像分割的性能评估——Keras?
- ms-access - 将表单控件链接到类
- c# - EF Core:参数化查询需要未提供的参数“@responseMessage”
- c# - 无法从 CSV 读取
- php - Laravel 5.7:如何从嵌套的 Eloquent 关系中递归获取属性?
- reactjs - 在 React 中为 Button 组件添加禁用属性