brainstorming
brainstorming
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).
typescript-refactorTypeScript and TSX refactoring and modernization guidelines from a principal specialist perspective, current to TypeScript 6.0 and React 19. This skill should be used when refactoring, reviewing, or modernizing TypeScript or React/TSX code for type safety, compiler performance, and idiomatic patterns. Triggers on tasks involving type architecture, narrowing…
Independent GitHub snapshot · Automated classification · Original documentation governs
Comprehensive TypeScript and TSX refactoring and modernization guide designed for AI agents and LLMs. Contains 47 rules across 9 categories, prioritized by impact to guide automated refactoring, code review, and code generation. Current to TypeScript 6.0 and React 19.
Reference these guidelines when:
as casts.tsx filessatisfies, using, const type parameters, inferred type predicates, erasable syntax, with import attributes)isolatedDeclarations, project references)| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Type Architecture | CRITICAL | arch- |
| 2 | Type Narrowing & Guards | CRITICAL | narrow- |
| 3 | Modern TypeScript | HIGH | modern- |
| 4 | React & TSX | HIGH | tsx- |
| 5 | Generic Patterns | HIGH | generic- |
| 6 | Compiler Performance | MEDIUM-HIGH | compile- |
| 7 | Error Safety | MEDIUM | error- |
| 8 | Runtime Patterns | MEDIUM | perf- |
| 9 | Quirks & Pitfalls | LOW-MEDIUM | quirk- |
arch-discriminated-unions — Use discriminated unions over string enums for exhaustive pattern matchingarch-branded-types — Use branded types for domain identifiers to prevent value mix-upsarch-satisfies-over-annotation — Use satisfies for config objects to preserve literal typesarch-interfaces-over-intersections — Extend interfaces instead of intersecting types for better error messagesarch-const-assertion — Use as const for immutable literal inferencearch-readonly-by-default — Default to readonly types for function parameters and return valuesarch-avoid-partial-abuse — Avoid Partial<T> abuse for builder patternsnarrow-custom-type-guards — Replace as with runtime-checked guards; TS 5.5+ infers the predicatenarrow-assertion-functions — Use assertion functions for precondition checksnarrow-exhaustive-switch — Enforce exhaustive switch with nevernarrow-in-operator — Narrow with the in operator for interface unionsnarrow-eliminate-as-casts — Eliminate as casts with proper narrowing chainsmodern-using-keyword — Use the using keyword for resource cleanupmodern-const-type-parameters — Use const type parameters for literal inferencemodern-template-literal-types — Use template literal types for string patternsmodern-noinfer-utility — Use NoInfer to control type parameter inferencemodern-verbatim-module-syntax — Enable verbatimModuleSyntax for explicit import typesmodern-erasable-syntax — Prefer erasable syntax over enums and namespaces for type-strippingmodern-import-attributes — Use with import attributes instead of deprecated asserttsx-avoid-react-fc — Type props directly instead of React.FCtsx-ref-as-prop — Pass ref as a prop instead of forwardRef (React 19)tsx-extend-native-props — Extend native element props with ComponentPropsWithRef instead of redeclaring themtsx-discriminated-props — Model mutually-exclusive props as discriminated unionstsx-event-handler-types — Type event handlers with React synthetic event typestsx-hook-typing — Type useState/useRef for nullable and mutable stategeneric-constrain-dont-overconstrain — Constrain generics minimallygeneric-avoid-distributive-surprises — Control distributive conditional typesgeneric-mapped-type-utilities — Build custom mapped types for repeated transformationsgeneric-return-type-inference — Preserve return type inference in generic functionscompile-explicit-return-types — Add explicit return types to exported functionscompile-avoid-deep-recursion — Avoid deeply recursive type definitionscompile-project-references — Use project references for monorepo buildscompile-base-types-over-unions — Use base types instead of large union typescompile-isolated-declarations — Enable isolatedDeclarations for parallel declaration emiterror-result-type — Use Result types instead of thrown exceptionserror-exhaustive-error-handling — Use exhaustive checks for typed error variantserror-typed-catch — Type catch clause variables as unknownerror-discriminated-error-unions — Model domain errors as discriminated unionsperf-union-literals-over-enums — Use union literals instead of enums — enums are non-erasableperf-avoid-delete-operator — Avoid the delete operator on objectsperf-object-freeze-const — Use Object.freeze with as const for true immutabilityperf-object-keys-narrowing — Avoid Object.keys type wideningperf-map-set-over-object — Use Map and Set over plain objects for dynamic collectionsquirk-excess-property-checks — Understand excess property checks on object literalsquirk-empty-object-type — Avoid the {} type — it means non-nullishquirk-structural-typing-escapes — Guard against structural typing escape hatchesquirk-variance-annotations — Use variance annotations to document generic intent (not for speed)Read individual reference files for detailed explanations and code examples:
| File | Description |
|---|---|
| references/_sections.md | Category definitions and ordering |
| assets/templates/_template.md | Template for new rules |
| metadata.json | Version and reference information |