# TypeScript — JavaScript with Syntax for Types > TypeScript is a superset of JavaScript that adds static types, interfaces, generics, and modern ES features, compiled down to plain JavaScript. Created by Anders Hejlsberg at Microsoft. Used by Airbnb, Slack, Asana, and a huge share of modern web projects. ## Install Save the content below to `.claude/skills/` or append to your `CLAUDE.md`: ## Quick Use ```bash # Install globally npm i -g typescript # Or in a project npm i -D typescript npx tsc --init ``` Example: ```ts // user.ts interface User { id: number; email: string; role: "admin" | "user"; } function greet(user: User): string { return `Hello, ${user.email} (${user.role})`; } const me: User = { id: 1, email: "w@tokrepo.com", role: "admin" }; console.log(greet(me)); ``` Compile: ```bash npx tsc # Compile once npx tsc --watch # Watch mode npx tsc --noEmit # Type-check only ``` `tsconfig.json` essentials: ```json { "compilerOptions": { "target": "ES2022", "module": "ESNext", "moduleResolution": "bundler", "strict": true, "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, "declaration": true, "outDir": "dist" }, "include": ["src/**/*"] } ``` ## Intro TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. Designed by Anders Hejlsberg (also creator of C# and Turbo Pascal) at Microsoft. First released in 2012, now used in most large-scale web projects. TypeScript makes JavaScript scalable for teams and big codebases by catching type errors at compile time and providing world-class IDE autocomplete and refactoring. - **Repo**: https://github.com/microsoft/TypeScript - **Stars**: 108K+ - **License**: Apache 2.0 ## What TypeScript Does - **Static types** — interfaces, type aliases, unions, intersections - **Generics** — parameterized types for reusable code - **Type inference** — infer types from values and signatures - **Type narrowing** — refine types via checks (typeof, instanceof, discriminators) - **Utility types** — Partial, Required, Pick, Omit, Record, Awaited - **Declaration files** — `.d.ts` for typing existing JS libraries - **Module resolution** — classic, node, bundler strategies - **JSX support** — TSX for React, Vue, Solid - **Project references** — incremental builds across packages - **Strict mode** — strict null checks, no implicit any ## Architecture TSC compiler written in TypeScript itself. Parses source to AST, performs type checking using a structural type system, then emits JavaScript. Language Server (tsserver) powers IDE features via LSP. ## Self-Hosting Language tool, ships via npm. ## Key Features - Structural type system - Type inference - Generics - Discriminated unions - Utility types - Declaration files for JS libraries - JSX/TSX support - Project references - Incremental builds - Rich LSP integration ## Comparison | Language | Types | Compiles To | Runtime | |---|---|---|---| | TypeScript | Static + inference | JavaScript | Node/Browser/Bun/Deno | | Flow | Static | JavaScript | Same | | Hegel | Static | JavaScript | Same | | ReScript | Static | JavaScript | Same | | PureScript | Static | JavaScript | Same | | Elm | Static | JavaScript | Browser | ## FAQ **Q: When should I use TypeScript?** A: Any JS project beyond 1000 lines, team size > 1, or long-term maintenance. Small scripts can skip it. **Q: Must I enable strict mode?** A: Strongly recommended. Turning off strict mode essentially discards TypeScript's core value. Use `@ts-expect-error` to annotate temporary exceptions. **Q: Slow compilation?** A: v5+ introduces project references and incremental builds. For large projects use `tsc -b` build mode. You can also use swc or esbuild for transformation only and skip type checking (combined with a separate `tsc --noEmit` check). ## Sources - Docs: https://www.typescriptlang.org/docs - GitHub: https://github.com/microsoft/TypeScript - License: Apache 2.0 --- Source: https://tokrepo.com/en/workflows/typescript-javascript-syntax-types-1b748b68 Author: Script Depot