TypeScript code examples
6 short, tested snippets. Pick one to see the code with notes, or search Zest for something specific, such as “typescript interface vs type”.
- Interface vs typeinterface User {
- Generic functionfunction first<T>(items: T[]): T | undefined {
- Union types and narrowingtype Shape =
- Utility typestype User = { id: number; name: string; email: string };
- Type a fetch responsetype Item = { id: number; title: string };
- Hello worldconst greeting: string = "Hello, World!";