this.service = () => { -- statements -- }
it("should service call",()=>{ // i want to call the arrow function here like component.service.? what to use in place of '?'. })
这是一个函数,所以你可以立即调用它:
的例子:
interface Service {
fun: () => string;
}
class Component {
constructor() {
this.service = () => {
return {
fun: () => 'hello'
};
};
}
service: () => Service;
}
调用:
const component = new Component();
const service = component.service();
const message = service.fun();
// or in one line:
const message = new Component().service().fun();
Typescript playground示例