admin管理员组文章数量:1430600
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
3 Answers
Reset to default 3Am 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.
本文标签: javascriptTypeScript error Reserved word 39this39 used as nameStack Overflow
版权声明:本文标题:javascript - TypeScript error: Reserved word 'this' used as name - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745486147a2660391.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论