DEV Community

Discussion on: Type-safe React using TypeScript

Collapse
 
alekseiberezkin profile image
Aleksei Berezkin • Edited

Interfaces can be augmented. What does it mean: if you export an interface, someone who imports it can literally add members to it without modifying your code. Why? Mainly for globals like Window (interface of window): you import it, augment, and further have typesafe global in your whole app. And this is done without modifying library which exports Window for your.

As a consequence, much of TypeScript metaprogramming does not work with interfaces β€” because they can be augmented, there's little sense in keyof Window (result can be anything), or in trying to create mapped interfaces (only mapped types possible).