我有这个功能:
network = (action): void =>{
if (action) {
this.action = action;
this.net = true;
this.netd = true;
} else {
this.action = null;
this.net = false;
this.netd = false;
}
}
我试图定义一个接口(interface),但它对我不起作用:
interface IStateService {
network: (action: string): void;
}
我收到一条消息说“unexpected token”无效
最佳答案
函数类型接口(interface)成员的语法有两个选项,它们在这里是等价的:
interface IStateService {
network: (action: string) => void;
}
或
interface IStateService {
network(action: string): void;
}
关于typescript - 如何在 Typescript 接口(interface)中为函数定义返回类型 void?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24988956/