knowledge icon indicating copy to clipboard operation
knowledge copied to clipboard

Extend typedef rule to support arrow functions

Open estankovic opened this issue 7 years ago • 1 comments

Motivation

When defining functions, that are actually constants using arrow function, current typecheck does not check whether those functions have return type

Proposal

I suggest extending typedef rule to support arrow-call-signature

...
"typedef": [
  true,
  "call-signature",
  "parameter",
  "arrow-call-signature"
],
...

Impact

This will mean that functions defined following way will need to have return type

const uselessFunction = (text: string) => {
  return 'I am super useless'
};

Should be:

const uselessFunction = (text: string): string => {
  return 'I am super useless'
};

Pros

Improved code readability


Links and References

https://palantir.github.io/tslint/rules/typedef/

estankovic avatar Nov 21 '19 12:11 estankovic

I've implemented it on the website and it requires tslint ignore comment to the *.routing.ts as with "new" routing syntax

  {
    path: 'wololo',
    loadChildren: () => // <-- here it wants a typing
      import('./wololo/wololo.module').then(m => m.WololoModule),
  },

I'd recommend using // tslint:disable: typedef on these "routing" files

vmasek avatar Jan 29 '20 12:01 vmasek