alivirgo/major-ai-skills/typescript
Claude Code and agent skill by alivirgo/major-ai-skills
- community
Checking that the SKILL.md file is still in the repository.
Ship strict TypeScript with sound tsconfig (NodeNext/Bundler), unknown-at-boundaries narrowing, discriminated unions, satisfies, and runtime validation—without silencing errors with any or unsafe assertions.
Install
npx vskill@latest install alivirgo/major-ai-skills/typescriptSKILL.md
TypeScript Type-Safe JavaScript AI Skill Guide (Claude)
Overview & Engine Architecture
TypeScript adds a structural type system that erases at compile time. The compiler (tsc) and language service enforce contracts; `tsconfig.json` chooses module resolution, emit, and strictness. Agents prefer precise types over any, model closed states with discriminated unions, validate untrusted input at runtime (types do not exist at runtime), and fix errors at API boundaries instead of silencing them with assertions.
When to use / when not to
Use when
- Adding or tightening types in app/library code; designing public function/API surfaces.
- Choosing
tsconfig(strict,NodeNextvsBundler,noUncheckedIndexedAccess). - Typing fetch/API payloads without lying to the compiler; migrating JS → TS incrementally.
Do not use when
- The task is purely runtime Node HTTP wiring with no type work →
@nodejs/@express. - Schema/DB generation is the center of gravity →
@prisma(consume generated types here). - Someone asks to blanket
// @ts-nocheck, globalany, oras unknown as Tto “make CI green” without fixing the boundary → refuse the silencing; fix or isolate with a typed adapter.
Operational Capabilities & Agent Directives
- Enable `strict: true` for application code; add `noUncheckedIndexedAccess` for arrays/records (index →
T | undefined). - Prefer `unknown` over `any` at boundaries; narrow before use (or parse with Zod/Valibot).
- Model closed states with discriminated unions (
type: 'loading' | 'ok' | 'err'). - Avoid
asassertions unless you can state why the compiler cannot prove the truth; prefersatisfiesfor literal checking without widening. - Match module mode to runtime: Node →
module/moduleResolutionNodeNext (relative imports need.jsextensions in source); Vite/Next bundlers → Bundler (do not mix conflicting modes). - Keep
skipLibCheck: trueas pragmatism for deps; still type your code correctly. - Gate with
npx tsc --noEmit(and project references in monorepos) before calling typed work done.
Production Example: boundary parse + app tsconfig
tsconfig.json (Node app — typecheck only):
Bundler / @nextjs apps: use the framework’s generated config; typically moduleResolution: "bundler"—do not force NodeNext relative .js rules into a Webpack/Turbopack graph unless the project already did.
Commands:
Pair with @nodejs for runtime ESM/CJS, @express/@nextjs for HTTP frameworks, @prisma for generated DB types.
Technical Troubleshooting Matrix
| Signature | Likely cause | Fix path | |
|---|---|---|---|
Cannot find module './foo' under NodeNext | Missing .js extension in relative import | Import ./foo.js (points at emit); or switch to Bundler mode for bundler apps | |
X is possibly undefined on arr[0] | noUncheckedIndexedAccess | Guard / optional chain / definite length check | |
| Runtime crash, types green | Trusted as / no runtime parse | Validate unknown at edge (Zod); stop lying with assertions | |
Library types “broken” with strict: false | Forked TS expectations | Turn strict on; fix incrementally with paths allowlist if needed | |
| Dual package hazard / CJS default import | Wrong interop settings | Align module with package "type"; prefer named ESM exports | |
| Emit works locally, Node fails | module/target ≠ runtime | Match Node version; use NodeNext for native ESM | |
CI only fails on tsc | IDE using different tsconfig | Pin -p in scripts; same TS version in CI |
Best Practices
export typefor type-only exports; withverbatimModuleSyntax, useimport type.- Prefer
satisfiesfor config objects: check shape without widening inferred type. - Generate types from OpenAPI/GraphQL when APIs change often (
@graphql-apis). - In React (
@react), type props explicitly; follow team stance onReact.FC. - Incremental strictness: enable flags per package rather than drowning a legacy tree in
any.
Limitations
- Type correctness ≠ runtime correctness—validation still required at trust boundaries.
- Declaration files for untyped deps may be incomplete or wrong.
exactOptionalPropertyTypesandnoUncheckedIndexedAccesscatch real bugs but increase friction—adopt deliberately.- Path aliases (
paths) need runtime mirrors (bundler/Node loaders) or they typecheck-only.
Related Skills
@nodejs— runtime modules TypeScript compiles to@express/@nextjs— common app hosts and their tsconfig conventions@react— component/hook typing@prisma— generated client types for DB access@graphql-apis— schema-driven types and codegen
Agent Operational Directive
MANDATORY: Keepstricton for new app code. Preferunknown+ narrowing (or Zod) overany/as. Alignmodule/moduleResolutionwith Node vs bundler. Runtsc --noEmitbefore declaring typed work complete. Do not “fix” CI by disabling checks globally.
Source anchors (research)
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/typescript/SKILL.md
Popularity
- Repository stars
- 1
- 7-day trend score
- 3
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/alivirgo/major-ai-skills/typescript)