Munge
Munge

Reputation: 824

Eslint arrow function, expected to have type annotation

so I have the following code:

public someFunctionName = (someParam: someType): void => {
    ...some code
};

When I run eslint on the file I get the error: expected someFunctionName to have a type annotation.

The only way that I can find to solve this is to remove the arrow function and replace with a regular function.

Does anyone know how to fix this problem for arrow functions?

Upvotes: 1

Views: 3248

Answers (1)

bvj
bvj

Reputation: 3392

Type-defining the function signature may help:

type SomeFuncType = (a: number) => void;

const someFunc: SomeFuncType = (a: number): void => {
  //
};

Also helps when exporting callback types.

I've recently dropped all uses of tslint, and adopted typescript-eslint instead. This includes removal of the VS Code tslint extension. Prettier is pretty much my choice these days.

Upvotes: 2

Related Questions