Instruction file imported from carrot-foundation/middle-earth (
.cursor/rules/typescript.mdc). Copyright stays with the author.
TypeScript (Middle Earth)
Compiler and language
- Respect
tsconfig.base.json:stricttrue,verbatimModuleSyntax,noUnusedLocals/Parameters. - Use the provided path aliases (
@middle-earth/libs/publishable/*); do not import via relative../../... - No
anyor unsafe casts; favor precise types and narrowing.
Modules and barrels
- Import from library barrels (
src/index.ts). Avoid deep imports into internal files. - Keep public types exported from the barrel.
Functions and variables
- Prefer explicit function return types for exported functions and public APIs.
- Meaningful identifiers; no 1-2 letter names; avoid abbreviations unless industry-standard.
- Use early returns and narrow unions with type guards.
- Organize constants, helpers, and types by file:
*.constants.ts,*.helpers.ts,*.types.ts.
Error handling
- Use
Result-like patterns or typed errors. Do not swallow errors; add context. - Prefer
type-festutility types where possible.
Lint integration
- Follow root ESLint config (Airbnb base/typescript, SonarJS, Unicorn, Security, Promise, Perfectionist, Prettier).
- Avoid default exports unless required by a framework (e.g., Next.js pages/layouts).