Mostly interchangeable for object shapes. `interface` supports declaration merging and `extends` chains efficiently — prefer it for public API contracts and class implementations. `type` can express unions, intersections, tuples, mapped/conditional types, primitives — required for anything beyond plain objects. Pick one as the default for your codebase and stay consistent.
Category
TypeScript
Generics, conditional types, inference, and design patterns.
3 questions
Generics parameterize types over types — use them for collections, hooks, and API wrappers. Utility types (`Partial`, `Pick`, `Omit`, `Record`, `ReturnType`, etc.) transform existing types instead of redeclaring them. Narrowing turns broad unions into specific types via `typeof`, `in`, discriminated unions, and user-defined type predicates. Together they let one function safely serve many shapes.
Three strategies: (1) write the library in TypeScript and ship `.d.ts` from build — best for new code; (2) hand-author `.d.ts` alongside JS — pragmatic for existing JS libs; (3) DefinitelyTyped (`@types/foo`) — community-maintained, used when you don't control the library. Use `tsd` / `expect-type` for type tests; treat types as part of the API surface.