我有这个功能:
network = (action): void =>{
if (action) {
this.action = action;
this.net = true;
this.netd = true;
} else {
this.action = null;
this.net = false;
this.netd = false;
}
}
Run Code Online (Sandbox Code Playgroud)
我试图定义一个界面,但它不适合我:
interface IStateService {
network: (action: string): void;
}
Run Code Online (Sandbox Code Playgroud)
我在消息上收到一条消息"意外令牌"
Rya*_*ugh 37
对于函数类型的接口成员,您有两种语法选项,它们在此处等效:
interface IStateService {
network: (action: string) => void;
}
Run Code Online (Sandbox Code Playgroud)
要么
interface IStateService {
network(action: string): void;
}
Run Code Online (Sandbox Code Playgroud)
这接近“类型文字”语法,但需要大括号:
interface IStateService {
network: { (action: string): void; }
}
Run Code Online (Sandbox Code Playgroud)
这是完整的语法,并允许定义重载,如下所示:
interface IStateService {
network: {
(): string;
(action: string): void;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13107 次 |
| 最近记录: |