Skip to content

Commit 71f00d1

Browse files
authored
Note that object literals may only specify known properties
Re: microsoft/TypeScript#49500
1 parent 246798d commit 71f00d1

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ greet(dog); // OK
7070
Note that `dog` has an extra `owner` property, but this does not create an error.
7171
Only members of the target type (`Pet` in this case) are considered when checking for compatibility.
7272

73+
Be aware, however, that [object literals](https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes-func.html#other-important-typescript-types)
74+
may only specifiy known properties. For example, because we have explicitly specified that `dog` is
75+
of type `Pet`, the following code is invalid:
76+
77+
```ts
78+
let dog: Pet = { name: "Lassie", owner: "Rudd Weatherwax" }; // Error
79+
```
80+
7381
This comparison process proceeds recursively, exploring the type of each member and sub-member.
7482

7583
## Comparing two functions

0 commit comments

Comments
 (0)