Skip to content

Commit 0b1f8ab

Browse files
Note that object literals may only specify known properties (#2421)
Co-authored-by: Jake Bailey <[email protected]>
1 parent d3b2be5 commit 0b1f8ab

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

packages/documentation/copy/en/reference/Type Compatibility.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,17 @@ greet(dog); // OK
6868
```
6969

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

73-
This comparison process proceeds recursively, exploring the type of each member and sub-member.
75+
Be aware, however, that object literals [may only specify known properties](/docs/handbook/2/objects.html#excess-property-checks).
76+
For example, because we have explicitly specified that `dog` is
77+
of type `Pet`, the following code is invalid:
78+
79+
```ts
80+
let dog: Pet = { name: "Lassie", owner: "Rudd Weatherwax" }; // Error
81+
```
7482

7583
## Comparing two functions
7684

0 commit comments

Comments
 (0)