Search code examples
javascriptnode.jstypescriptwebstormkeyword

TypeScript error: Reserved word 'this' used as name


I am trying to get this Node.js TypeScript definition to work, but WebStorm gives me a big list of errors with all the same message:

Reserved word 'this' used as name. This inspection reports on any uses of JavaScript reserved words being used as a name. The JavaScript specification reserves a number of words which are currently not used as JavaScript keywords. Using those words as identifiers may result in broken code if later versions of JavaScript use them as keywords.

An example piece of code where this error happens due to the return type:

Error example

Why can't the this keyword be a type? Am I perhaps using an old TypeScript compiler or is it a mistake in the typing?


Edit: To get rid of the errors I've just replaced all these this types with the type of the containing class or interface. For example, the errors in the given example are fixed by changing it to this:

export interface EventEmitter {
    addListener(event: string, listener: Function): EventEmitter;
    ...
}

Although, this is not a solution to the actual problem.


Solution

  • Seems you use old version of WebStorm. WebStorm supports 'this' type starting from v11.0.3.