使用双箭头功能es6编写打字稿界面的语法是什么?
JS示例:
const myFunction => (param1) => (param2) => {
...code
}
示例:TS:
const myFunc = (param1: number) => (param2: number) => {
return param1 + param2
};
此界面不正确
interface myInterface {
myFunc: (param1: number) => (param2: number) => number
}
错误是:Parsing error: ';' expected
所以为什么?正确的语法是什么?
答案 0 :(得分:1)
我怀疑错误是由您的Javascript引起的。
const myFunction => (param1) => (param2) => {
...code
}
那不是合法的JS。你是说:
const myFunction = (param1) => (param2) => {
...code
}
其余的编译器对我来说还不错:
interface MyInterface {
myFunc: (param1: number) => (param2: number) => number
}
const Foo: MyInterface = {
myFunc: (param1: number) => (param2: number) => {
return param1 + param2
}
}
class FooClass implements MyInterface {
myFunc(param1: number) {
return (param2: number) => {
return param1 + param2;
}
}
}