1

I am translating a huge AMD JS project to TypeScript and I have noticed I have problems with the following things:

  • keyword function introduces a lot of problems because of "this" scope. I always replace all functions with arrow style functions
  • class methods - if a pointer to a method is sent as a parameter to another function and then called - it is also problematic, so I replace those with arrow functions as well.

I mean, when I do it - there is no problem whatsoever. But my issue is that sometimes I forget to do it and TS never shows me any error, because as a matter of fact it's not a error. So is it possible to make TS show me a warning in those cases?

shal
  • 2,110
  • 3
  • 15
  • 25
  • 3
    Probably not. Functions are a part of the language and there's no reason for the compiler to complain about that. Also, using arrow functions isn't always a good idea, especially in classes if you intend to override methods – Nitzan Tomer Apr 12 '17 at 14:21
  • are you using tslint? – Suraj Rao Apr 12 '17 at 14:22
  • @NitzanTomer, I must emphasize that I recognize all the problems that I may encounter, however I'd like to be able to do it now, at least until I translated the entire project and made sure everything works as it worked before translation. – shal Apr 12 '17 at 15:04

1 Answers1

1

One possible solution exists if you are using tslint.

You can add the following rule to tslint.json:

"only-arrow-functions": [true, "allow-declarations", "allow-named-functions"]

Link:docs

Also as @NitzanTomer suggests arrow functions are ideal for only certain cases

Community
  • 1
  • 1
Suraj Rao
  • 28,186
  • 10
  • 88
  • 94