typescript
Skill20 starsChanged 7 months agoMITView on GitHub
Apply when writing TypeScript code. Strict types, discriminated unions, async patterns, and runtime safety.
33 other projects use a version of this.
Adopted by
Most recently taken up by
- Quad4-Software/skillstheir own version, first seen Oct 3, 2026
- lobehub/lobehubtheir own version, first seen Oct 1, 2026
- jscraik/Agent-Skillstheir own version, first seen Sep 27, 2026
- wolzey/agent-factorytheir own version, first seen Sep 23, 2026
- microsoft/scopetheir own version, first seen Sep 23, 2026
- AvilaCarlosDev/openclaw-skillstheir own version, first seen Sep 19, 2026
Used with
Projects with it also use security.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
0xSeroSkillsecurity
Also in 4 projects that use this
Other versions33 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 33
- lobehub/lobehub★ 83ksame name
- microsoft/fast★ 9.7ksame name
- alinaqi/maggy★ 707same name
- Mindrally/skills★ 266same name
- martinholovsky/claude-skills-generator★ 47same name
- nimadorostkar/Claude-Skills-collection★ 28same name
- siviter-xyz/dot-agent★ 22same name
- alexander-danilenko/cortex-ai-skills★ 16same name
- caidanw/skills★ 9same name
- joabgonzalez/ai-agents-skills★ 9same name
23 more not listed
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 repository49 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .cursor/rules/brainstorming.mdcCursor rule
- .cursor/rules/branch-finishing.mdcCursor rule
- .cursor/rules/code-quality.mdcCursor rule
- .cursor/rules/db-schema.mdcCursor rule
- .cursor/rules/debugging.mdcCursor rule
- .cursor/rules/docker.mdcCursor rule
- .cursor/rules/domain-template.mdcCursor rule
- .cursor/rules/drawio.mdcCursor rule
- .cursor/rules/error-log.mdcCursor rule
- .cursor/rules/fastapi.mdcCursor rule
- .cursor/rules/git-conventions.mdcCursor rule
- .cursor/rules/github-cli.mdcCursor rule
- .cursor/rules/implementation-plan.mdcCursor rule
- .cursor/rules/langchain.mdcCursor rule
- .cursor/rules/python.mdcCursor rule
- .cursor/rules/react.mdcCursor rule
- .cursor/rules/review-deployment.mdcCursor rule
- .cursor/rules/security-review.mdcCursor rule
- .cursor/rules/self-extension-workflow.mdcCursor rule
- .cursor/rules/shell-scripting.mdcCursor rule
- .cursor/rules/svg-check.mdcCursor rule
- .cursor/rules/tdd.mdcCursor rule
- .cursor/rules/typescript.mdcCursor rule
- skill-everythingSkill
- brainstormingSkill
- branch-finishingSkill
- code-qualitySkill
- db-schemaSkill
- debuggingSkill
- dockerSkill
- domain-templateSkill
- drawioSkill
- error-logSkill
- fastapiSkill
- git-conventionsSkill
- github-cliSkill
- implementation-planSkill
- langchainSkill
- pythonSkill
- reactSkill
- review-deploymentSkill
- security-reviewSkill
- self-extension-workflowSkill
- shell-scriptingSkill
- svg-checkSkill
- tddSkill
- <kebab-case-name>Skill
The file
We split this skill into the rules it gives an agent
1 rule. 0 are common, 0 are distinctive, and 1 is very specific to this project.
0
Common
Most of the 27 edited versions we read keep these.
0
Distinctive
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 27
Where these rules don't strictly apply: test fixtures, generated types (e.g.
“Common” is measured: kept by at least 6 in 10 of the 27 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
Sub-Skill: TypeScript Best Practices
<!-- target: ~2500 tokens (real tiktoken count) | 17 rules with severity classification -->Purpose: Prevents the TypeScript-specific mistakes LLMs make repeatedly — weak types, unsafe assertions, and patterns that compile but fail at runtime.
Rule classification
- MUST — load-bearing. Violating leaks runtime errors past the type checker. Never break.
- SHOULD — default behavior. Deviation needs a documented reason in the code or PR.
- AVOID — usually wrong; documented exception inline where needed.
Where these rules don't strictly apply: test fixtures, generated types (e.g. from GraphQL codegen, OpenAPI generators, Prisma), declaration files (*.d.ts) for untyped third-party libraries, and migration scripts may legitimately differ. The rules below apply to production application code.
Type Safety
- MUST: Never use
any. Useunknownand narrow it.anydisables the type checker entirely.unknownforces you to prove the type before use. Exception: third-party libraries without types and explicit dynamic-data boundaries (e.g. JSON parse at the API edge), with a comment explaining why.// Wrong function parse(data: any) { return data.name; } // Correct function parse(data: unknown): string { if (typeof data === 'object' && data !== null && 'name' in data) { return String((data as { name: unknown }).name); } throw new Error('Invalid data shape'); } - AVOID:
Objector{}as a type. Both accept nearly everything. UseRecord<string, unknown>for arbitrary objects or define an explicit interface.// Wrong function merge(a: {}, b: Object): {} { ... } // Correct function merge<T extends Record<string, unknown>>(a: T, b: Partial<T>): T { ... } - SHOULD: Use
asonly when you know more than the compiler — and document why. Prefer type guards orsatisfiesinstead.// Wrong — silences the error, hides the bug const user = response.data as User; // Correct — validate first function isUser(v: unknown): v is User { return typeof v === 'object' && v !== null && 'id' in v && 'email' in v; } const user = isUser(response.data) ? response.data : null; - SHOULD: Mark immutable data
readonly. Prevents accidental mutation and communicates intent.// Avoid function process(ids: string[]) { ids.push('extra'); } // Prefer function process(ids: readonly string[]) { /* ids.push() is a compile error */ } - MUST: Enable
strictNullChecksand handle everyT | undefined. Optional chaining?.returnsundefined— always handle that branch.// Wrong const name = user?.profile.name.toUpperCase(); // crashes if name is undefined // Correct const name = user?.profile.name?.toUpperCase() ?? 'Anonymous'; - SHOULD: Use branded types for IDs. Prevents passing a
UserIdwhere anOrderIdis expected — both arestringat runtime.type UserId = string & { readonly _brand: 'UserId' }; type OrderId = string & { readonly _brand: 'OrderId' }; function createUserId(raw: string): UserId { return raw as UserId; } function getUser(id: UserId): User { ... } // getUser(orderId) → compile error
Patterns
- SHOULD: Use discriminated unions for state, not optional fields. Optional fields force you to reason about all combinations. A discriminated union makes illegal states unrepresentable.
// Avoid — 8 possible combinations, most invalid type Request = { loading?: boolean; data?: User; error?: Error }; // Prefer — exactly 3 valid states type Request = | { status: 'idle' } | { status: 'loading' } | { status: 'success'; data: User } | { status: 'error'; error: Error }; - SHOULD: Use
satisfiesto validate shape without widening the type.as constpreserves literals;satisfiesvalidates against an interface without losing them.const config = { host: 'localhost', port: 5432, } satisfies DatabaseConfig; // config.port is still typed as 5432, not number - SHOULD: Use
constobjects instead ofenum. Enums emit runtime code, have surprising reverse-mapping behavior, and are not idiomatic TypeScript.// Avoid enum Direction { Up, Down, Left, Right } // Prefer const Direction = { Up: 'Up', Down: 'Down', Left: 'Left', Right: 'Right' } as const; type Direction = typeof Direction[keyof typeof Direction]; - AVOID: Barrel
index.tsre-exports in large modules. They cause circular dependency chains that are hard to debug. Export directly from source files or use explicit named re-exports only.// Wrong — index.ts re-exports everything, A imports B through index, B imports A through index export * from './userService'; export * from './orderService'; // Correct — import directly import { getUser } from './services/userService';
Error Handling
- MUST: Type your thrown errors explicitly.
catch (e)gives youunknownin strict mode. Narrow before accessing properties.try { await fetchUser(id); } catch (e) { // Wrong: e.message — e is unknown // Correct: const message = e instanceof Error ? e.message : String(e); logger.error('fetchUser failed', { message, id }); } - SHOULD: Use
Resulttypes for expected failures instead of throwing. Throwing for control flow forces callers to know which functions throw and what.type Result<T, E = Error> = { ok: true; value: T } | { ok: false; error: E }; function parseConfig(raw: string): Result<Config> { try { return { ok: true, value: JSON.parse(raw) }; } catch (e) { return { ok: false, error: e instanceof Error ? e : new Error(String(e)) }; } }
Performance
- MUST: Use
Promise.allfor independent async operations, not sequentialawait. Sequential awaits multiply latency.// Wrong — 300ms total if each takes 100ms const user = await getUser(id); const orders = await getOrders(id); const prefs = await getPrefs(id); // Correct — 100ms total const [user, orders, prefs] = await Promise.all([ getUser(id), getOrders(id), getPrefs(id), ]); - SHOULD: Use
Promise.allSettledwhen partial failure is acceptable.Promise.allrejects on the first failure.allSettledcollects all results.const results = await Promise.allSettled(ids.map(fetchItem)); const succeeded = results .filter((r): r is PromiseFulfilledResult<Item> => r.status === 'fulfilled') .map(r => r.value);
Testing
- MUST: Type test helpers and mocks — never use
as anyto silence mock errors. Untyped mocks let type errors hide until runtime. Exception: prototyping spikes that are explicitly thrown away before merge.// Wrong const mockUser = { id: '1' } as any; // Correct const mockUser: User = { id: createUserId('1'), email: 'a@b.com', name: 'Alice' }; - SHOULD: Test the discriminated union branches explicitly. Each
statusvariant is a separate code path. One test per branch minimum.it('renders error state', () => { const state: Request = { status: 'error', error: new Error('timeout') }; render(<RequestView state={state} />); expect(screen.getByRole('alert')).toHaveTextContent('timeout'); }); - SHOULD: Use
expectTypeOforassertTypefor type-level tests. Runtime tests cannot catch type regressions.import { expectTypeOf } from 'vitest'; expectTypeOf(createUserId('x')).toEqualTypeOf<UserId>();
Why This Sub-Skill Earns Stars
These rules target the gap between "TypeScript that compiles" and "TypeScript that is safe". LLMs default to any, skip discriminated unions, and reach for as assertions because they are the path of least resistance. Each rule here closes a specific escape hatch that lets type errors reach production. The MUST/SHOULD/AVOID classification means safety-critical rules are strict and stylistic rules respect context.
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.

