typescript-idioms
Learn TypeScript's type system as your specification: enable strict mode, use type guards over casts, and validate all external data with Zod. This skill covers discriminated unions for state machines, immutability patterns, null safety, and the critical rule that all HTTP calls route through a centralized client for consistent auth and error handling.
TypeScript Idioms teaches strict mode, type narrowing, and runtime validation patterns to make invalid states unrepresentable.
AI-generated summary based on this skill's SKILL.md
Decision gist · record as of 2026-07-17
TypeScript Idioms teaches strict mode, type narrowing, and runtime validation patterns to make invalid states unrepresentable. Learn TypeScript's type system as your specification: enable strict mode, use type guards over casts, and validate all external data with Zod. This skill covers discriminated unions for state machines, immutability patterns, null safety, and the critical rule that all HTTP calls route through a centralized client for consistent auth and error handling.
Use it when
- typescript-idioms emphasizes that all HTTP calls must route through a centralized client for consistent auth and error handling.
- typescript-idioms stresses that `unknown` is the type-safe alternative to `any`.
Verify before relying
Read SKILL.md below before installing (2 files). Open directory: indexed for reading, not audited.
Install
irahardianto/awesome-agv/typescript-idioms · repository language: JavaScript
Open directory. Skills are indexed for reading, not audited. Review a skill's body before installing it.
Frequently asked questions
AI-generated answers based on this skill's SKILL.md and metadata
What are typescript strict mode best practices?
typescript-idioms teaches that strict mode is your specification layer. Enable `strict: true` in tsconfig.json to enforce non-null checks, explicit `any` rejection, and sound property initialization. Use type guards (`typeof`, `instanceof`, custom predicates) instead of non-null assertions. Validate all external data—especially API responses—with Zod at boundaries. This prevents runtime surprises by catching type errors at compile time.
How do you implement runtime validation at API boundaries using Zod?
typescript-idioms emphasizes that all HTTP calls must route through a centralized client for consistent auth and error handling. At that boundary, use Zod schemas to parse and validate responses before your code consumes them. Define a schema matching your API contract, call `.parse()` or `.safeParse()`, and reject invalid data. This ensures type safety isn't just a compile-time illusion—runtime data is verified before it enters your type system.
What is the difference between unknown vs any in typescript?
typescript-idioms stresses that `unknown` is the type-safe alternative to `any`. Both accept any value, but `unknown` requires you to narrow the type before use—via type guards, `typeof` checks, or custom predicates—forcing explicit validation. `any` bypasses all checks and defeats the type system. Use `unknown` for external data, function parameters you can't predict, and error objects. Reserve `any` only for legacy code or unavoidable third-party gaps.
How do you build type-safe state machines with discriminated unions?
typescript-idioms teaches discriminated unions as the pattern for state machines. Define a union of state types, each with a literal `type` or `status` field that differs. TypeScript's type narrowing then automatically refines the union when you check that discriminant. For example, `type State = { type: 'idle' } | { type: 'loading'; request: Promise<Data> } | { type: 'error'; message: string }`. This makes illegal state transitions impossible at compile time.
What role do readonly and immutability patterns play in typescript?
typescript-idioms advocates readonly to encode immutability in your types. Mark object properties and array types as `readonly` to prevent accidental mutations and signal intent. Use `as const` assertions on literals to infer the narrowest possible types. Immutability reduces bugs, makes concurrent code safer, and pairs well with functional patterns. Combined with strict mode and type guards, readonly enforces a discipline that catches mutation errors before runtime.
How should you configure ESLint and Vitest for typescript production code?
typescript-idioms covers tooling integration: configure ESLint with `@typescript-eslint/parser` and `@typescript-eslint/recommended` rules to catch common mistakes. Enable Vitest with TypeScript support and mock external dependencies consistently. Use type checking in your CI pipeline alongside tests. This layered approach—linting, type checking, unit tests, and centralized HTTP clients—catches errors early and ensures your production code stays type-safe and maintainable.
SKILL.md
Rendered from the published skill. Quoted content, verbatim.
TypeScript Idioms and Patterns
Core Philosophy
TypeScript's type system is your documentation, your test, and your specification — all at once. Make the type system encode the invariants of your domain so that invalid states are unrepresentable. Lean into the compiler.
> Scope: This file covers TypeScript-specific type system and language idioms. For framework-specific patterns, see the respective idiom skill (Vue, React, Angular, Next.js, Hono). For file layout, see references/project-structure.md in this skill. For quality commands, see code-idioms-and-conventions.md. For logging library, see @.agents/skills/logging-implementation/SKILL.md.
Strict Mode — Non-Negotiable
Always enable strict mode in tsconfig.json:
{
"compilerOptions": {
"strict": true,
"noUncheckedIndexedAccess": true,
"exactOptionalPropertyTypes": true
}
}
These flags catch the majority of runtime errors at compile time. Never disable them on a per-file basis
(truncated - see the full file via the links below)
File tree — 2 files
.agents/skills/typescript-idioms/SKILL.md
.agents/skills/typescript-idioms/references/project-structure.md
Let your AI agent find skills like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 56,283 agent skills by what they can do, searchable in plain language.
wish › “Learn TypeScript type system idioms and strict mode best practices”
Give your agent the search over MCP, or paste the wish link into any chat. No install? Search from any chat →
Related skills
Learn idiomatic Hono patterns for building type-safe HTTP APIs across any runtime. This skill covers router composition, middleware ordering, request validation with Zod, error handling, and end-to-end typed RPC clients—all without code generation.
Learn idiomatic Angular through signals, standalone components, and reactive patterns. This skill covers modern Angular 19+ practices including OnPush change detection, signal-based state management, functional guards and resolvers, and template control flow syntax. Covers components, services, directives, pipes, and routing for TypeScript-based Angular projects.
This skill covers idiomatic PHP 8.x development, emphasizing strict typing, immutable data structures via readonly classes and enums, and domain-driven error handling. Learn named arguments, match expressions, constructor injection, and PSR-12 naming conventions alongside static analysis tools like PHPStan and Psalm.
Learn idiomatic C# patterns that leverage type safety, LINQ expressiveness, and async-first design. This skill covers modern features like nullable reference types, records, and pattern matching, plus practical guidance on error handling, dependency injection, and testing with xUnit.
This skill establishes a TypeScript development environment with strict compiler options, ESLint rules, and Jest test coverage. It provides project structure templates, tooling configuration, and GitHub Actions workflows to maintain code quality and type safety across your codebase.
This skill covers the core patterns that make Swift code safe and maintainable. You'll learn when to use structs over classes, how to handle optionals without crashes, design with protocols instead of inheritance, and leverage Swift's concurrency model. The guide includes practical examples of error handling, property wrappers, actors, and testing strategies—plus anti-patterns to avoid.