1

What is the syntax to write a typescript interface using double arrow function es6?

Example JS:

const myFunction => (param1) => (param2) => {
...code
}

Example: TS:

const myFunc = (param1: number) => (param2: number) => {
  return param1 + param2
};

this interface is incorrect

interface myInterface {
   myFunc: (param1: number) => (param2: number) => number
}

the error is: Parsing error: ';' expected so why? and what is the correct syntax?

Ernane Luis
  • 353
  • 2
  • 9
  • that interface is correct, unless you wanted https://typescript-play.js.org/#code/JYOwLgpgTgZghgYwgAgLYE8CS5rycgbwChlSAKABzijlQEYAuZEAV1QCNoBKJy62gExNWHbsgC8APmZtOUIgF8A3ESIATCAgA21FAgD2IAM5hkkE0wzZIsRBBXmwZAKxcXXIA – Shanon Jackson Jul 05 '19 at 02:27
  • The interface looks correct according to what you provided for Example JS. – Rich Jul 05 '19 at 04:26
  • Does this answer your question? [What do multiple arrow functions mean in JavaScript?](https://stackoverflow.com/questions/32782922/what-do-multiple-arrow-functions-mean-in-javascript) – Michael Freidgeim May 29 '21 at 13:03

1 Answers1

1

I suspect the error is coming from your Javascript.

const myFunction => (param1) => (param2) => {
...code
}

That is not legal JS. Did you mean:

const myFunction = (param1) => (param2) => {
...code
}

The rest compiles just fine for me:

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;
    }
  }

}
Pace
  • 41,875
  • 13
  • 113
  • 156