首页 > 解决方案 > 如何声明一个非箭头函数的函数定义类型?

问题描述

我有一个接口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[];

标签: typescript

解决方案


export interface Autocomplete {
  filterOptions(name: string): any[];
}

class Test implements Autocomplete {
    // VSCode implementation
    filterOptions(name: string): any[] {
        throw new Error("Method not implemented.");
    }
}

推荐阅读