Use when writing, editing, or reviewing TypeScript in a Node.js ESM project. Triggers on `.ts` files, ESM `package.json`, `import` paths, strict-mode type errors, async code, or environment variables, even when the user doesn't say 'TypeScript'.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Writing Typescript?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/xonovex-writing-typescript)
---
name: writing-typescript
description: "Use when writing, editing, or reviewing TypeScript in a Node.js ESM project. Triggers on `.ts` files, ESM `package.json`, `import` paths, strict-mode type errors, async code, or environment variables, even when the user doesn't say 'TypeScript'."
---
# TypeScript Coding Guidelines
Write strict TypeScript modules with explicit types, direct imports, and checked errors.
## Requirements
- Node.js ESM, TypeScript ≥ 5.8, Vitest ≥ 3, Zod ≥ 4.
## Essentials
- **Strict mode** - Enable strict flags, avoid `@ts-ignore` without comment+issue
- **Type safety** - Explicit public types, `unknown` over `any`, derive from generated types
- **Imports** - Use `import type` for type-only imports
- **Async/await** - Handle errors explicitly, only use `async` with `await`, see [references/async-without-await.md](references/async-without-await.md), [references/unnecessary-async-keywords.md](references/unnecessary-async-keywords.md)
- **Immutability** - Use `const`/`readonly` where possible
- **Validation** - Zod for I/O boundaries, infer types from schemas
- **Linting** - Never suppress with eslint-disable, fix root causes, see [references/avoid-eslint-disable.md](references/avoid-eslint-disable.md)
- **Template literals** - Convert numbers with `String(value)`, see [references/template-literals-require-string-conversion.md](references/template-literals-require-string-conversion.md)
- **Numeric literals** - Use underscores in large numbers (`30_000`), see [references/numeric-separator-enforcement.md](references/numeric-separator-enforcement.md)
- **Method references** - Keep object references to maintain `this` binding, see [references/unbound-method-references.md](references/unbound-method-references.md)
- **Environment** - Use dot notation for `process.env` access, see [references/env-access-bracket-notation.md](references/env-access-bracket-notation.md)
- **Paradigm** - Functional style → **applying-fp**; class/OO design → **applying-oop**
## Gotchas
- Structural typing means `{ a: string }` accepts `{ a: string, b: number }` silently: explicit `satisfies` is the way to catch unintended extras
- `as` casts bypass the type system without check: prefer narrowing functions (type predicates) over casts
- `type` vs `interface`: interfaces merge across declarations, types don't. `declare global { interface Window { ... } }` works, `type Window = ...` doesn't
- `unknown` is the safer `any`, but it doesn't propagate; narrowing once doesn't carry across assignments
- Module resolution depends on `tsconfig` `moduleResolution` (`bundler` vs `node16` vs `nodenext`): wrong choice silently breaks deep imports
## Progressive disclosure
- Read [references/async-without-await.md](references/async-without-await.md) - Load when seeing async functions that don't use await
- Read [references/unnecessary-async-keywords.md](references/unnecessary-async-keywords.md) - Load when simplifying synchronous controller functions
- Read [references/avoid-eslint-disable.md](references/avoid-eslint-disable.md) - Load when tempted to suppress linting warnings
- Read [references/template-literals-require-string-conversion.md](references/template-literals-require-string-conversion.md) - Load when inserting numbers in template literals
- Read [references/numeric-separator-enforcement.md](references/numeric-separator-enforcement.md) - Load when writing large numeric literals
- Read [references/unbound-method-references.md](references/unbound-method-references.md) - Load when passing methods as callbacks or references
- Read [references/env-access-bracket-notation.md](references/env-access-bracket-notation.md) - Load when accessing process.env variables
Files in this skill
SKILL.md3.6 KB
eval-output.json2.5 KB
eval-trigger.json5 KB
moon.yml86 B
references/async-without-await.md521 B
references/avoid-eslint-disable.md605 B
references/env-access-bracket-notation.md505 B
references/numeric-separator-enforcement.md396 B
references/template-literals-require-string-conversion.md393 B