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?

3

1 Answer 1

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

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.