1---2name: lang-typescript3description: lang-typescript4---5# lang-typescript67## Core Principles89- Prefer explicit types over `any`. If you need `any`, use `unknown` and narrow it.10- Favor `interface` for object shapes, `type` for unions, intersections, and mapped types.11- Keep functions pure where possible. Isolate side effects at the edges.12- Angular: keep components thin. Business logic belongs in services, not templates or components.1314## Reference1516| Resource | When to use |17|----------|-------------|18| `./references/types.md` | Type system patterns: generics, utility types, type guards, narrowing |19| `./references/errors.md` | Error handling: typed errors, Result pattern, RxJS error streams |20| `./references/async.md` | Async patterns: Promises, async/await, RxJS Observables |21| `./references/project-structure.md` | Angular and Node project layouts |2223## MUST DO2425- Enable `strict: true` in `tsconfig.json`26- Type all function parameters and return values explicitly27- Use `readonly` on properties that should not be mutated28- Unsubscribe from Observables in Angular components (use `takeUntilDestroyed` or `DestroyRef`)29- Inject dependencies via constructor in Angular services, not `inject()` at module level30- Use `const` by default; `let` only when reassignment is necessary3132## MUST NOT3334- Use `any` — use `unknown` and narrow, or define a proper type35- Subscribe inside a subscribe (use `switchMap`, `mergeMap`, etc.)36- Mutate objects passed as inputs or function arguments37- Use `@ts-ignore` without a comment explaining why38- Use `setTimeout` for async coordination — use Promises or Observables instead3940## Agent Behavior4142- Before creating a new service or component, use tree-sitter `find_similar_code` to detect existing patterns that could be reused or extended.43- Use tree-sitter `find_usage: subscribe` to locate all Observable subscriptions and verify each has a corresponding `takeUntilDestroyed` or `DestroyRef` teardown.44- Use tree-sitter `find_usage: any` for a targeted audit of `any` type usages before enforcing strict types.45- Use tree-sitter `get_symbols(symbol_types: ["functions", "classes"])` to map a module's public surface before modifying its interface.