Skip to content

Commit 221198b

Browse files
authored
Update Object Types.md with interface extension details
1 parent 9ec526c commit 221198b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

packages/documentation/copy/en/handbook-v2/Object Types.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,8 +617,27 @@ declare const staffer: Staff;
617617
staffer.name;
618618
// ^?
619619
```
620+
620621
In this case, Staff would require the name property to be both a string and a number, which results in property being of type `never`.
621622

623+
624+
625+
In comparison, extending interfaces with incompatible properties produces a compile-time error:
626+
```ts twoslash
627+
interface Person1 {
628+
name: string;
629+
}
630+
631+
interface Person2 {
632+
name: number;
633+
}
634+
635+
interface Staff extends Person1 , Person2 {}
636+
```
637+
Unlike intersection types, interface extension requires properties with the same name to have compatible types.
638+
639+
640+
622641
## Generic Object Types
623642

624643
Let's imagine a `Box` type that can contain any value - `string`s, `number`s, `Giraffe`s, whatever.

0 commit comments

Comments
 (0)