TypeScript Ecosystem
This skill should be used when the user asks to "write typescript", "typescript config", "tsconfig", "type definition", "generics", "utility types", or works with TypeScript language patterns and configuration. Provides comprehensive TypeScript ecosystem patterns and best practices.
$ インストール
git clone https://github.com/takeokunn/nixos-configuration /tmp/nixos-configuration && cp -r /tmp/nixos-configuration/home-manager/programs/claude-code/skills/typescript-ecosystem ~/.claude/skills/nixos-configuration// tip: Run this command in your terminal to install the skill
name: TypeScript Ecosystem description: This skill should be used when the user asks to "write typescript", "typescript config", "tsconfig", "type definition", "generics", "utility types", or works with TypeScript language patterns and configuration. Provides comprehensive TypeScript ecosystem patterns and best practices.
<strict_options>
<module_resolution> Modern Node.js ESM resolution (recommended) { "compilerOptions": { "module": "nodenext", "moduleResolution": "nodenext" } } Requires "type": "module" in package.json
<project_references> Monorepo and incremental builds { "compilerOptions": { "composite": true, "incremental": true, "tsBuildInfoFile": ".tsbuildinfo" }, "references": [ { "path": "../shared" }, { "path": "../core" } ] } Use tsc --build for incremental compilation </project_references>
<type_patterns> <utility_types> Make all properties optional Make all properties required Make all properties readonly Object type with key K and value V Select specific properties from T Exclude specific properties from T Exclude types from union Extract types from union Remove null and undefined Get function return type Get function parameter types as tuple Unwrap Promise type </utility_types>
<conditional_types> Basic conditional type type IsString<T> = T extends string ? true : false;
<mapped_types> Basic mapped type type Readonly<T> = { readonly [P in keyof T]: T[P]; };
<template_literal_types>
Template literal type construction
type EventName = on${Capitalize<string>};
type Locale = ${Language}-${Country};
<type_guards> Built-in typeof type guard function process(value: string | number) { if (typeof value === "string") { return value.toUpperCase(); } return value.toFixed(2); }
function isCat(pet: Cat | Dog): pet is Cat { return (pet as Cat).meow !== undefined; } <decision_tree name="when_to_use"> Does TypeScript need help narrowing union types? <if_yes>Implement custom type guard with is predicate</if_yes> <if_no>Use built-in typeof or instanceof guards</if_no> </decision_tree>
<branded_types> Nominal typing via branding type UserId = string & { readonly **brand: unique symbol }; type OrderId = string & { readonly **brand: unique symbol };
function createUserId(id: string): UserId { return id as UserId; } Prevent mixing similar primitive types </branded_types>
<satisfies_operator> Type checking without widening const config = { endpoint: "/api", timeout: 3000, } satisfies Record<string, string | number>; // config.endpoint is inferred as "/api" (literal), not string </satisfies_operator> </type_patterns>
<runtime_patterns> <error_handling> Rust-inspired Result type for error handling type Result<T, E = Error> = | { success: true; data: T } | { success: false; error: E };
function parseJson<T>(json: string): Result<T> { try { return { success: true, data: JSON.parse(json) }; } catch (e) { return { success: false, error: e as Error }; } } <decision_tree name="when_to_use"> Do you need explicit error handling without exceptions? <if_yes>Use Result type for functional error handling</if_yes> <if_no>Use try-catch for traditional exception handling</if_no> </decision_tree>
<async_patterns> Parallel promise execution const [users, posts] = await Promise.all([ fetchUsers(), fetchPosts(), ]);
const successful = results .filter((r): r is PromiseFulfilledResult<User> => r.status === "fulfilled") .map((r) => r.value);
for await (const item of paginate(fetchUsers)) { console.log(item); } </async_patterns>
<module_patterns> ES module export patterns // Named exports export const helper = () => {}; export type Config = { /* ... _/ };
// Default export export default class Service {}
// Re-exports export { util } from "./util.js"; export type { UtilOptions } from "./util.js";
export default tseslint.config( eslint.configs.recommended, ...tseslint.configs.strictTypeChecked, { languageOptions: { parserOptions: { projectService: true, tsconfigRootDir: import.meta.dirname, }, }, } ); import.meta.dirname requires Node.js 20.11+ or 21.2+ (not available in Node.js 18 LTS)
<key_rules> Prefer unknown over any Detect unused variables Require explicit boolean conditions Require awaiting promises Use ?? over || </key_rules>
export default defineConfig({ test: { globals: true, environment: "node", coverage: { provider: "v8", reporter: ["text", "json", "html"], }, }, });
const config: Config = { preset: "ts-jest", testEnvironment: "node", roots: ["<rootDir>/src"], moduleNameMapper: { "^@/(.*)$": "<rootDir>/src/$1", }, };
export default config;
<build_tools> TypeScript compiler commands <use_case name="compile">tsc - Compile TypeScript</use_case> <use_case name="build">tsc --build - Incremental build (monorepo)</use_case> <use_case name="check">tsc --noEmit - Type check only</use_case> <use_case name="watch">tsc --watch - Watch mode</use_case>
export default defineConfig({ entry: ["src/index.ts"], format: ["cjs", "esm"], dts: true, clean: true, sourcemap: true, }); </build_tools>
<context7_integration> <library_id>/microsoft/typescript</library_id> <trust_score>9.9</trust_score> 16397
<usage_pattern> Resolve library ID if needed (already known: /microsoft/typescript) Fetch documentation with specific topic Configuration options and patterns Generic type patterns Built-in utility types Module resolution strategies </usage_pattern>
<common_queries> Strict compiler options Path aliases configuration Type declaration generation ESM support in Node.js </common_queries> </context7_integration>
<anti_patterns> Overusing 'any' defeats type safety Use 'unknown' and narrow with type guards
type Status = (typeof Status)[keyof typeof Status];
<best_practices> Enable strict mode in all projects Use noUncheckedIndexedAccess for safer array/object access Prefer 'unknown' over 'any' for unknown types Use 'satisfies' to check types without widening Create branded types for domain primitives Use Result types for error handling over exceptions Keep type definitions close to usage Export types separately with 'export type' Use 'const' assertions for literal types Prefer interfaces for public APIs, types for unions/utilities </best_practices>
<error_escalation> Minor type inference issue Add explicit type annotation Type error in implementation Fix type, verify with tsc Breaking type change in public API Stop, present migration options to user Type safety bypass with any or type assertion Block operation, require proper typing </error_escalation>
<related_agents> API design, type system architecture, and module structure planning TypeScript implementation with strict type checking and configuration setup ESLint validation, type safety checks, and best practices enforcement </related_agents>
<related_skills> Symbol-level navigation for type definitions and interfaces Fetch latest TypeScript compiler and tooling documentation Debug type errors and investigate compilation issues </related_skills>
Repository
