Skill v1.0.0
currentLLM-judged scan90/100version: "1.0.0" name: typescript-safety description: > Makes TypeScript catch more bugs at compile time on TS 6 and 7: tsconfig flags past strict, narrowing and discriminated unions, exhaustive switches, generics and inference (satisfies, const type parameters, NoInfer), utility, mapped, conditional, and template literal types, branded types, unknown at data edges, replacing any, as, ! and ts-ignore, typescript-eslint type-checked rules, Node type stripping and erasableSyntaxOnly, and the upgrade from TS 5 or 6 to 7. Use when editing tsconfig.json, fixing a type error, removing any or casts, designing the types for a module, or when a TS 6 or 7 upgrade breaks the build. Not for React rendering (react-performance), Next.js caching and routing (nextjs-app-router), or validating request bodies with Zod (api-security).
TypeScript safety
Getting the compiler to catch bugs before they run, on TypeScript 6 and 7. TS 7.0 is the Go compiler, installed as plain typescript since July 2026. strict has been the default since 6.0, so the remaining gains come from the flags strict leaves off, from narrowing instead of casting, and from parsing data at the edges.
Types describe code, not data. Anything that enters the process (a response body, JSON.parse, storage, env vars) is unchecked until code checks it. An annotation on an any is a cast.
Every escape hatch turns off the check that would have caught the bug. No any in new code. Reach for unknown and narrow. A cast needs a runtime check next to it.
Source checks and dates: SOURCES.md.
Procedure
- Read the project's
tsconfig.jsonand the installedtypescriptversion (npx tsc --version). On 5.x or 6.x with deprecation errors, start with upgrade-6-to-7.md. - Compare the config with the baseline in config.md. Turning on a flag in an old codebase can add hundreds of errors: count them with
tsc --noEmitfirst, and fix by module. - Read the resource for the task in the table below.
- Write the change. Prefer the first tool that works: narrowing, then a predicate, then a checked cast.
- Run
tsc --noEmit, andeslintif the project has typed linting. Report both results, and say which TS version ran.
data from outside ──> unknown ──> parse at the edge ──> precise types insidedomain-types.md narrowing.md, generics.md|tsconfig flags catch the rest: config.md types from types: type-level.md|any / as / ! found? escape-hatches.md lint what tsc cannot: linting.md
Where to read
| Task | Resource | |
|---|---|---|
tsconfig defaults, the baseline, flags past strict, module by runtime, the empty types default | config.md | |
| Upgrading to 6.0 and 7.0, removed options and syntax, running TS 6 next to 7 | upgrade-6-to-7.md | |
| Discriminated unions, exhaustive switches, predicates, assertion functions, unsound spots | narrowing.md | |
When a type parameter earns its place, constraints, satisfies, const type parameters, NoInfer | generics.md | |
Utility types, the Omit trap, mapped, conditional, and template literal types, augmentation | type-level.md | |
Untyped data at the edges, branded IDs and units, readonly inputs | domain-types.md | |
any, as, !, @ts-expect-error, and what to use instead | escape-hatches.md | |
| typescript-eslint configs and rules, and the TS 6 alias the linter still needs | linting.md | |
Node type stripping, erasableSyntaxOnly, verbatimModuleSyntax, enums | node-and-emit.md |
The traps that cost the most time
| Symptom | Usual cause | Read | |
|---|---|---|---|
Cannot find name 'process' after upgrading | types defaults to [] since 6.0 | config.md | |
| TS5011, common source directory | outDir is set, sources sit under src/, and rootDir is unset | config.md | |
| TS5102 or TS5108, "has been removed" | An option TS 7 dropped: baseUrl, moduleResolution: node, target: es5, outFile | upgrade-6-to-7.md | |
| typescript-eslint breaks after installing TS 7 | import 'typescript' on 7 is only the version. Alias TS 6 for the linter. | linting.md | |
| A typed value is wrong at runtime | any from .json() or JSON.parse assigned to a typed variable | domain-types.md | |
arr[0].x crashes on an empty array | noUncheckedIndexedAccess is off | config.md | |
| A new union member is silently ignored | The switch has no exhaustive check | narrowing.md | |
Renamed field still listed in an Omit, no error | Omit does not check its keys | type-level.md | |
A literal list types as string[] | No as const or const type parameter | generics.md | |
| A wrong value is accepted by a generic function | Another argument widens T. Wrap it in NoInfer. | generics.md | |
ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX from Node | An enum, parameter property, or runtime namespace | node-and-emit.md | |
does not provide an export named from Node | A type imported without import type | node-and-emit.md | |
| A narrowed property is wrong after a call | Narrowing is not reset by function calls | narrowing.md | |
| TS2775 on an assertion function call | The function is a const with no type annotation | narrowing.md |
Review checklist
- [ ]
strict,noUncheckedIndexedAccess,exactOptionalPropertyTypes, andverbatimModuleSyntaxare on, andtarget,module, andtypesare explicit - [ ] No option or syntax removed in TS 7 remains
- [ ] Data from outside is
unknownuntil parsed, once, at the edge - [ ] No
anyin new code. Everyassits behind a runtime check. No@ts-ignore. - [ ] States with different fields are discriminated unions, and switches over them are exhaustive
- [ ] A function type parameter appears at least twice. An inferred return counts. A type alias may use its parameter once.
- [ ] IDs and units that can be mixed up are branded
- [ ] typescript-eslint runs a type-checked config
- [ ] The report names the TS version and shows the
tsc --noEmitresult