This repository was archived by the owner on Oct 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Added section on excess property checking #148
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -20,6 +20,7 @@ printLabel(myObj); | |||
The type-checker checks the call to `printLabel`. | |||
The `printLabel` function has a single parameter that requires that the object passed in has a property called `label` of type string. | |||
Notice that our object actually has more properties than this, but the compiler only checks that *at least* the ones required are present and match the types required. | |||
There are some cases where TypeScript isn't as lenient as we'll go over in a bit. |
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.
I think "... isn't as lenient, which we'll cover in a bit." is easier to read.
Ping |
👍 after you address a typo and a minor comment |
DanielRosenwasser
added a commit
that referenced
this pull request
Feb 16, 2016
Added section on excess property checking
let mySquare = createSquare(squareOptions); | ||
``` | ||
|
||
Since `squareOptions` won't undergo excess property checks, the compiler won't give you an error. |
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.
I do not think this should be our recommendation; the recommendation would be to either use cast or use a contextual type with union types for all possible variations.
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.
And probably mention the compiler flag to disable the error reporting.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #64.
Fixes microsoft/TypeScript#6175.