-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Conversation
|
||
How `this` works in JavaScript functions is a common theme in programmers coming to JavaScript. | ||
Indeed, learning how to use it is something of a rite of passage as developers become more accustomed to working in JavaScript. | ||
Learning how to use `this` in JavaScript is something of a rite of passage. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed :)
|
||
## `this` parameters | ||
|
||
Unfortunately, by default TypeScript will still type `this` in `this.suits[pickedSuit]` as `any`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we make it sound less negative. i mean that there is a default behavior that is there because this is JS, and there is an optional stricter checking mode that users can, and should opt in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, the stricter checking of --noImplicitThis
will just point out the problem -- --strictThisChecks
did not ship.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about changing this line and the next to:
Unfortunately, the type of this.suits[pickedSuite]
is still any
.
That's because this
comes from the function expression inside the object literal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I reworded it to the above.
on a related note, can you file an issue for updating lib.d.ts to use |
Where does that issue go? TypeScript or TSJS-lib-generator? |
Typescript seems more visible. |
👍 |
--noImplicitThis
this
and arrow functionsFixes #310