Apply a version fact only to the version the project uses. Upgrade TypeScript only when the user asks.
- Capture the full compiler output before you change code. Use the project's type-check script, or
npx tsc --noEmit when it has none.
- Find the root cause as the
debugging block requires. Typical causes are unsound inference, a missing constraint, an implicit any, or a widened literal.
- Fix the cause with the simplest precise type. Replace each
any with a real type, and check that every call site still compiles.
- Run the type check again and read the output, as the
verification block requires.
Prefer a plain type, a union, or an overload over a type-level construct when both express the same contract. Keep the type changes inside the scope of the task.
These five facts matter most when a project moves to TypeScript 6 or 7.
- TypeScript 6.0 changed the defaults. Now
strict is true, module is esnext, types is [], and rootDir is the directory of tsconfig.json.
- Every option that TypeScript 6.0 deprecates is a hard error in 7.0. Examples are
baseUrl, moduleResolution node, target es5, and downlevelIteration.
- Move to 6.0 first and fix each deprecation error. The
ignoreDeprecations setting only hides them in 6.0.
- TypeScript 7.0 has no programmatic API. Tools that import
typescript, such as typescript-eslint, still need the @typescript/typescript6 package.
- An omitted
types list no longer loads every @types package. List global packages such as node explicitly.
Read typescript-6-7.md before you edit a tsconfig.json, upgrade TypeScript, or fix errors that appeared after an upgrade.
function getProperty(obj: any, key: string): any {
return obj[key];
}
A generic key constraint keeps the link between the key and the value type. With it, getProperty({ name: "Alice" }, "name") returns string.
function getProperty<T, K extends keyof T>(obj: T, key: K): T[K] {
return obj[key];
}
async function fetchUser(): Promise<any> {
const res = await fetch("/api/user");
return res.json();
}
The fix types the response as unknown and narrows it with a type guard before it returns. The guard runs at the system boundary, where code_rules asks for validation.
interface User { id: number; name: string }
function isUser(value: unknown): value is User {
return (
typeof value === "object" &&
value !== null &&
"id" in value &&
typeof value.id === "number" &&
"name" in value &&
typeof value.name === "string"
);
}
async function fetchUser(): Promise<User> {
const res = await fetch("/api/user");
const data: unknown = await res.json();
if (!isUser(data)) throw new Error("Invalid user shape");
return data;
}
1---2name: typescript3description: Writes and fixes TypeScript types and compiler settings. Use it whenever a task adds or changes types, generics, type guards, branded types, or utility types, and when tsc reports a type error. Use it to replace `any` with a strict type. Use it when editing tsconfig.json, choosing module, target, or resolution settings, or upgrading to TypeScript 6 or 7 with the Go-based native compiler.4metadata:5 source: https://skillmd.com/skills/dayfinggg/typescript6---78<project_first>9Follow the project before this skill, as `code_rules` requires. Read the `tsconfig.json` files the code uses, including every file in the `extends` chain. Find the installed TypeScript version in the lockfile or in `node_modules/typescript/package.json`. Read how nearby code already writes types, such as brands, guards, schema libraries, and helper types. Reuse those patterns.1011Apply a version fact only to the version the project uses. Upgrade TypeScript only when the user asks.12</project_first>1314<boundary>15This skill covers types, type errors, and compiler configuration. Running TypeScript inside Node.js, with type stripping or a loader, belongs to the `node` skill. JavaScript language features, browser code, and React belong to the `javascript` skill.16</boundary>1718<workflow>19A type problem takes four steps.20211. Capture the full compiler output before you change code. Use the project's type-check script, or `npx tsc --noEmit` when it has none.222. Find the root cause as the `debugging` block requires. Typical causes are unsound inference, a missing constraint, an implicit `any`, or a widened literal.233. Fix the cause with the simplest precise type. Replace each `any` with a real type, and check that every call site still compiles.244. Run the type check again and read the output, as the `verification` block requires.2526Prefer a plain type, a union, or an overload over a type-level construct when both express the same contract. Keep the type changes inside the scope of the task.27</workflow>2829<upgrade_facts>30TypeScript 7.0 is the Go-based native compiler, released in July 2026. It ships in the standard `typescript` package and keeps the `tsc` command. In November 2026 the latest stable release is 7.0.2, and 7.1 is in beta.3132These five facts matter most when a project moves to TypeScript 6 or 7.3334- TypeScript 6.0 changed the defaults. Now `strict` is `true`, `module` is `esnext`, `types` is `[]`, and `rootDir` is the directory of `tsconfig.json`.35- Every option that TypeScript 6.0 deprecates is a hard error in 7.0. Examples are `baseUrl`, `moduleResolution` `node`, `target` `es5`, and `downlevelIteration`.36- Move to 6.0 first and fix each deprecation error. The `ignoreDeprecations` setting only hides them in 6.0.37- TypeScript 7.0 has no programmatic API. Tools that import `typescript`, such as typescript-eslint, still need the `@typescript/typescript6` package.38- An omitted `types` list no longer loads every `@types` package. List global packages such as `node` explicitly.3940Read [typescript-6-7.md](references/typescript-6-7.md) before you edit a `tsconfig.json`, upgrade TypeScript, or fix errors that appeared after an upgrade.41</upgrade_facts>4243<quick_examples>44<remove_any_with_generics>45This function loses all type information, because it takes and returns `any`.4647```ts48function getProperty(obj: any, key: string): any {49 return obj[key];50}51```5253A generic key constraint keeps the link between the key and the value type. With it, `getProperty({ name: "Alice" }, "name")` returns `string`.5455```ts56function getProperty<T, K extends keyof T>(obj: T, key: K): T[K] {57 return obj[key];58}59```60</remove_any_with_generics>6162<narrow_an_unknown_response>63This function returns `any` for data from the network.6465```ts66async function fetchUser(): Promise<any> {67 const res = await fetch("/api/user");68 return res.json();69}70```7172The fix types the response as `unknown` and narrows it with a type guard before it returns. The guard runs at the system boundary, where `code_rules` asks for validation.7374```ts75interface User { id: number; name: string }7677function isUser(value: unknown): value is User {78 return (79 typeof value === "object" &&80 value !== null &&81 "id" in value &&82 typeof value.id === "number" &&83 "name" in value &&84 typeof value.name === "string"85 );86}8788async function fetchUser(): Promise<User> {89 const res = await fetch("/api/user");90 const data: unknown = await res.json();91 if (!isUser(data)) throw new Error("Invalid user shape");92 return data;93}94```95</narrow_an_unknown_response>96</quick_examples>9798<rules>99Each rule file explains one technique with examples. Read a file when the task needs that technique.100101<core_patterns>102- [references/as-const-typeof.md](references/as-const-typeof.md) derives types from runtime values with `as const` and `typeof`. Read it when one object should define both values and types.103- [references/array-index-access.md](references/array-index-access.md) gets element types with `[number]`. Read it when you need a union of the items in an array or tuple.104- [references/utility-types.md](references/utility-types.md) covers `Parameters`, `ReturnType`, `Awaited`, `Omit`, `Partial`, `Record`, and related types. Read it when you wrap a function or derive a type from another type.105</core_patterns>106107<advanced_generics>108- [references/generics-basics.md](references/generics-basics.md) covers type parameters, constraints, defaults, and inference. Read it when a generic loses information or infers `unknown`.109- [references/builder-pattern.md](references/builder-pattern.md) tracks state in the type of a chainable builder. Read it when a fluent API must remember earlier calls.110- [references/deep-inference.md](references/deep-inference.md) keeps literal types in nested arguments with `const` type parameters. Read it when a config object widens to `string` or `string[]`.111</advanced_generics>112113<type_level_programming>114- [references/conditional-types.md](references/conditional-types.md) covers `extends ? :` logic and distribution over unions. Read it when a type depends on another type.115- [references/infer-keyword.md](references/infer-keyword.md) extracts parts of a type with `infer`. Read it when you need the element, argument, or return type of something.116- [references/template-literal-types.md](references/template-literal-types.md) builds and parses string types. Read it for typed routes, event names, or key renames.117- [references/mapped-types.md](references/mapped-types.md) transforms each property of a type, with key remapping and modifiers. Read it when a new type follows the shape of another type.118</type_level_programming>119120<type_safety_patterns>121- [references/opaque-types.md](references/opaque-types.md) brands primitives so different IDs or validated strings cannot mix. Read it when values share a primitive type but mean different things.122- [references/type-narrowing.md](references/type-narrowing.md) covers control-flow narrowing, type predicates, assertion functions, and exhaustive checks. Read it when a union or `unknown` value needs a specific type.123- [references/function-overloads.md](references/function-overloads.md) gives one function several call signatures. Read it when the return type depends on the argument type.124</type_safety_patterns>125126<debugging>127- [references/error-diagnosis.md](references/error-diagnosis.md) explains how to read long compiler errors and isolate their cause. Read it when an error message is long or unclear.128</debugging>129</rules>