typescript-magician
Skill1 starsChanged 58 days agoApache-2.0View on GitHub
Resolves TypeScript compiler errors and finds the smallest type that compiles under the pi-495 tsconfig (strict, `noUncheckedIndexedAccess`, `exactOptionalPropertyTypes`, `erasableSyntaxOnly`, `verbatimModuleSyntax`, TypeScript 7), through narrowing, discriminated unions and exhaustiveness, type guards, `as const` with `typeof` instead of enums, template-literal and branded identifiers, utility and mapped types, `infer`. Use when `npm run typecheck` fails, when a `!`, an `as` or an `any` is about to be written, when an identifier travels as a bare `string`, when a union needs exhaustiveness, or when a type must be derived from a value or from a TypeBox schema.
6 other projects use a version of this, 6 of them edited.
Adopted by
Most recently taken up by
- poizoncoded/skillsedited, first seen Nov 1, 2026
- sb-dev/narrative-production-skillsedited, first seen Oct 20, 2026
- KhaledSaeed18/node-express-boilerplateedited, first seen Jul 15, 2026
- ushibo/brigadeedited, first seen Jul 6, 2026
- itsyasirkhandev/spec-driven-developmentedited, first seen Jun 2, 2026
- mcollina/skillsedited, first seen Mar 13, 2026
Other versions6 projects use a version of this.
Word for word · 0
None found.
Edited · 6
- mcollina/skills★ 2k14% same
- KhaledSaeed18/node-express-boilerplate★ 3614% same
- poizoncoded/skills★ 214% same
- sb-dev/narrative-production-skills★ 214% same
- itsyasirkhandev/spec-driven-development★ 114% same
- ushibo/brigade★ 114% same
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository4 other files it gives its agents.
- AGENTS.mdAGENTS.md
- nodeSkill
- architecture-mapSkill
- architecture-recommendationSkill
The file
We split this skill into the rules it gives an agent
3 rules. 0 are common, 0 are distinctive, and 3 are very specific to this project.
0
Common
Most of the 6 edited versions we read keep these.
0
Distinctive
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 18
Run npm run typecheck and read the error bottom-up before changing anything (rules/error-diagnosis.md).
- Very specific: line 23
Write the smallest type that compiles.
- Very specific: line 30
Run npm run typecheck again, then the tests of the generation touched.
“Common” is measured: kept by at least 6 in 10 of the 6 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Provenance
Adapted from the typescript-magician skill of mcollina/skills (MIT, commit 856efd2 of 2026-08-17;
the licence is in ../LICENSE-mcollina-skills). The rules on chainable builders and on ts-toolbelt
deep inference were removed: the tree has neither and adds no type-level library.
Instructions
When invoked:
- Run
npm run typecheckand read the error bottom-up before changing anything (rules/error-diagnosis.md). - Name the cause: a missing narrowing, an index that may be
undefined, an optional property givenundefinedexplicitly, a type imported as a value, an enum or namespace refused byerasableSyntaxOnly, a generic without the constraint its call site needs. - Write the smallest type that compiles. One solution, not several. A union, a type guard or a
satisfiesdoes the job before a conditional or mapped type does; a type-level program is the last resort, not the first (CONVENTIONS.md§ Principles, 5: the minimum code that solves the stated problem). anynever.!only to assert an invariant the type cannot see, at the point that knows it (Biome'snoNonNullAssertionis off for that reason, and only that one).asonly towardunknown, or at a boundary the value has just been validated through.- Run
npm run typecheckagain, then the tests of the generation touched.
Explain the cause in one sentence in the code only when the type is not self-evident; the rest goes in the answer, not in a comment.
What the tsconfig implies
| Option | What it means when writing a type |
noUncheckedIndexedAccess | xs[i], record[key] are T | undefined: narrow with a check, .at(), or ! where the invariant is known → rules/type-narrowing.md, rules/array-index-access.md |
exactOptionalPropertyTypes | { a?: string } refuses { a: undefined }: omit the key, or declare a?: string | undefined on purpose |
erasableSyntaxOnly | a const object and (typeof X)[keyof typeof X], or a written-out string union, instead of an enum → rules/as-const-typeof.md |
verbatimModuleSyntax | import type for every type |
strict | an unknown at every boundary (JSON, a process's output, a Pi payload), narrowed by a guard before use |
Patterns already in the tree
- Contracts are TypeBox schemas under
src/contracts/; the type of a contract isStatic<typeof Schema>, never a hand-written twin.validateandcheckinsrc/contracts/narrow anunknownto it.npm run contractsre-emits the JSON schemas after a change there. - Closed unions as codes:
DomainErrorCodeis a written-out string union andCATEGORYaRecord<DomainErrorCode, ErrorCategory>, so adding a code without its category does not compile. Exhaustiveness over such a union goes through aswitchwith aneverdefault → rules/type-narrowing.md. - Identifiers with a shape are template-literal types (
type Digest = `sha256:${string}`) → rules/template-literal-types.md. An identifier that must not be confused with anotherstringof the same shape is a branded type → rules/opaque-types.md. - Fakes implement ports: a
Fake<Thing>intest/helpers/implements the interface ofsrc/ports/; a type error there usually means the port changed and the fake lags. - TypeScript 7 is the Go port:
tscand the flags are unchanged, thetypescriptnpm API is not the TypeScript 5 one (createSourceFileis absent).
Rules
Core patterns
- rules/as-const-typeof.md - Deriving types from runtime values with
as constandtypeof - rules/array-index-access.md - Element types through
[number]indexing - rules/utility-types.md -
Parameters,ReturnType,Awaited,Omit,Partial,Record
Generics
- rules/generics-basics.md - Generic types, constraints, inference
Type-level programming
- rules/conditional-types.md - Conditional types
- rules/infer-keyword.md - Extracting types with
infer - rules/template-literal-types.md - String shapes at the type level
- rules/mapped-types.md - Transforming the properties of a type
Type safety
- rules/opaque-types.md - Branded and opaque identifiers
- rules/type-narrowing.md - Narrowing, discriminated unions, exhaustiveness, guards
- rules/function-overloads.md - Overloads for signatures a union cannot express
Debugging
- rules/error-diagnosis.md - Reading and isolating a compiler error
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

