Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

This parameters #321

Merged
merged 5 commits into from
Jun 27, 2016
Merged

This parameters #321

merged 5 commits into from
Jun 27, 2016

Conversation

sandersn
Copy link
Member

  1. Document this parameters
  2. Document --noImplicitThis
  3. Merge (1) and (2) with existing discussion of this and arrow functions

Fixes #310


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.
Copy link
Contributor

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`.
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member Author

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.

@mhegazy
Copy link
Contributor

mhegazy commented Jun 27, 2016

on a related note, can you file an issue for updating lib.d.ts to use this parameters for event handlers.

@sandersn
Copy link
Member Author

Where does that issue go? TypeScript or TSJS-lib-generator?

@mhegazy
Copy link
Contributor

mhegazy commented Jun 27, 2016

Typescript seems more visible.

@sandersn
Copy link
Member Author

done, microsoft/TypeScript#9374

@mhegazy
Copy link
Contributor

mhegazy commented Jun 27, 2016

👍

@sandersn sandersn merged commit 819891d into release-2.0 Jun 27, 2016
@sandersn sandersn deleted the this-parameters branch June 27, 2016 17:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants