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

Added section on excess property checking #148

Merged
merged 3 commits into from
Feb 16, 2016
Merged

Conversation

DanielRosenwasser
Copy link
Member

@DanielRosenwasser
Copy link
Member Author

@sandersn @mhegazy @bowdenk7

@@ -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.
Copy link
Member

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.

@DanielRosenwasser
Copy link
Member Author

Ping

@sandersn
Copy link
Member

👍 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
@DanielRosenwasser DanielRosenwasser merged commit 87a2cb5 into master Feb 16, 2016
@DanielRosenwasser DanielRosenwasser deleted the excessProperties branch February 16, 2016 22:34
let mySquare = createSquare(squareOptions);
```

Since `squareOptions` won't undergo excess property checks, the compiler won't give you an error.
Copy link
Contributor

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.

Copy link
Contributor

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.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants