Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

'this' banned term conflicts with Typescript's function this-types #261

Closed
dsole opened this issue Sep 20, 2016 · 2 comments
Closed

'this' banned term conflicts with Typescript's function this-types #261

dsole opened this issue Sep 20, 2016 · 2 comments
Milestone

Comments

@dsole
Copy link

dsole commented Sep 20, 2016

I'm finding that the function level this-type introduced by Microsoft/TypeScript #6739 is triggering the "noReservedKeywords" rule.

Using this example from the PR

interface I {
  n: number;
  method: (m: number) => number;
}
function futureMethod(this: I, m: number) {
  return this.n + m;
}
let o: I = { n: 12, method: futureMethod };

The this-type feature of TS declares the futureMethod has having one parameter (m) and that the
"this" object within its scope implements interface I.
But instead it has a tslint error:

[tslint] Forbidden reference to reserved keyword: this
(parameter) this: I

It feels like a special exception is needed for the this keyword, to allow for function this-types.

@HamletDRC
Copy link
Member

I see that this rule will interface with the Polymorphic this Type described here: http://www.typescriptlang.org/docs/handbook/advanced-types.html

I don't see any official documentation on the feature you mention. Is it a TypeScript 2.0 feature?

@dsole
Copy link
Author

dsole commented Oct 2, 2016

Now that TS 2.0 is out, I can confidently say that yes it is going to be included.
They're mentioned in the release notes under "Specifying the type of this for functions"

@HamletDRC HamletDRC added this to the 2.0.14 milestone Oct 26, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants