4 ms·
You still can extend types with type intersections: type A = { id: number } type B = A & { name: string } const b: B = { id: 0, name: 'foo' }
by pietrovismara 5y ago
You still can extend types with type intersections:
type A = { id: number }
type B = A & { name: string }
const b: B = {
id: 0,
name: 'foo'
}
- moron4hire 5y agoThat's creating a new type B. In contrast, interfaces can have their definition spread across multiple code units. interface X { x(): void; } interface X { y(): void; } class Y implements X { x(): void { console.log("hello"); } y(): void { console.log("world"); } } const z = new Y(); z.x(); z.y(); This is important for keeping up with API changes in browsers that may happen faster than the DefinitelyTyped project can keep up.
- deleted 5y ago[deleted]