typescript - 如何声明一个非箭头函数的函数定义类型?
问题描述
我有一个接口Autocomplete
,我想在其中包含一个具有以下声明的方法:
export interface Autocomplete {
filterOptions: (name: string) => any[];
}
当我实现我的接口时,它给了我这个实现作为箭头函数:
filterOptions: (name: string) => any[];
我需要一个正常的函数声明,所以最后我会得到:
filterOptions(name:string) {
return any[];
}
我需要如何在界面中定义我的方法,这样我才能得到
filterOptions(name:string) {
return any[];
}
而不是箭头函数
filterOptions: (name: string) => any[];
解决方案
export interface Autocomplete {
filterOptions(name: string): any[];
}
class Test implements Autocomplete {
// VSCode implementation
filterOptions(name: string): any[] {
throw new Error("Method not implemented.");
}
}
推荐阅读
- reactjs - 使用两个端口在 Heroku 上部署 React APP
- javascript - Gravity Forms 带有美国国家代码的电话面罩
- vim - vim x/y 滚动条隐藏我的命令,真的很讨厌
- r - Prestige$type 中的错误:“闭包”类型的对象不是子集
- npm - 节点应用程序 - 有大量的哈希查找文件
- python - 将不同类型的缺失值转换为 pandas 可识别的 NA
- python - 如何更改 Seaborn 条形图中的标签字体大小?
- ruby-on-rails - Ruby on Rails 插入错误 ***** PG::InsufficientPrivilege: 错误: 关系发票的权限被拒绝
- python - python使用“模板列表”创建新列表
- r - 如何从 0 开始计算观察的出现次数并将其存储在 R 中的新变量中?