Skip to content

Note that object literals may only specify known properties #2421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions packages/documentation/copy/en/reference/Type Compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,17 @@ greet(dog); // OK
```

Note that `dog` has an extra `owner` property, but this does not create an error.
Only members of the target type (`Pet` in this case) are considered when checking for compatibility.
Only members of the target type (`Pet` in this case) are considered when
checking for compatibility. This comparison process proceeds recursively,
exploring the type of each member and sub-member.

This comparison process proceeds recursively, exploring the type of each member and sub-member.
Be aware, however, that object literals [may only specify known properties](/docs/handbook/2/objects.html#excess-property-checks).
For example, because we have explicitly specified that `dog` is
of type `Pet`, the following code is invalid:

```ts
let dog: Pet = { name: "Lassie", owner: "Rudd Weatherwax" }; // Error
```

## Comparing two functions

Expand Down