javascript - TypeScript error: Reserved word 'this' used as name - Stack Overflow

I am trying to get this Node.js TypeScript definition to work, but WebStorm gives me a big list of erro

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:

Why can't the this keyword be a type? Am I perhaps using an old TypeScript piler 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.

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:

Why can't the this keyword be a type? Am I perhaps using an old TypeScript piler 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.

Share Improve this question edited Mar 18, 2016 at 21:43 Duncan Lukkenaer asked Mar 18, 2016 at 20:39 Duncan LukkenaerDuncan Lukkenaer 14.1k18 gold badges71 silver badges107 bronze badges 2
  • 3 This looks like a bug in WebStorm. – SLaks Commented Mar 18, 2016 at 20:45
  • I think SLaks is right. It works fine for me in Atom. – rgvassar Commented Mar 18, 2016 at 21:04
Add a ment  | 

3 Answers 3

Reset to default 3

Am I perhaps using an old TypeScript piler ... ?

Yes, upgrade to at least TS 1.7 to get polymorphic this support.

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

The following code piles just fine in the typescript playground:

export interface E
{
    b(): this;
}

class A implements E
{
    public b(): any
    {
        return 123;
    }   
}

let a = new A();
console.log(a.b());

And according to link 'this' will be interpreted as 'any'. So most likely there is something with webstorm.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745486147a4629775.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信