domain:typescript

Enforce strict TypeScript conventions with zod validation and vitest tests.

Updated Jul 27, 2025
One-click install
npx skills add https://github.com/TheCactusBlue/nixfiles --skill domain-typescript
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: domain:typescript
Source: https://github.com/TheCactusBlue/nixfiles/tree/main/.claude/skills/domain%3Atypescript
Command: npx skills add https://github.com/TheCactusBlue/nixfiles --skill domain-typescript

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Consolidates TypeScript project conventions to ensure consistent type safety, robust testing, and standardized error handling across codebases.

Core Features & Use Cases

  • Enforce strict mode in tsconfig.json — no exceptions
  • Prefer const over let; never use var
  • Use discriminated unions for state modeling over class hierarchies
  • Prefer unknown over any — narrow types explicitly
  • Use readonly on properties and arrays that should not be mutated
  • Prefer interface for object shapes, type for unions and intersections
  • Use template literal types for string patterns where useful
  • Prefer satisfies operator to validate types without widening
  • Project structure: src directory, path aliases, barrel exports, colocate tests and types
  • Testing: vitest as the test framework; colocate tests with sources
  • Error Handling: typed error classes with a code; Result pattern; validate external input with zod
  • Dependencies: zod for runtime validation, date-fns for dates, native fetch or ofetch, eslint + prettier, tsup for libraries, vite for applications
  • Anti-patterns: avoid any, avoid deep barrel exports, avoid mutable shared state

Quick Start

Apply the conventions by enabling strict mode in tsconfig.json, preferring const over let, using unknown over any, and adopting vitest tests with zod validations.

Frequently Asked Questions about domain:typescript

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I enforce consistent TypeScript conventions for project structure and type safety?

To enforce TypeScript conventions, enable strict mode in tsconfig.json, use const over let, prefer unknown over any, and apply the Result pattern with zod for runtime validation to ensure maintainable project structure.

What is the best way to handle errors in a TypeScript project?

The best way to handle errors in TypeScript is using typed error classes with a code property and adopting the Result pattern, while validating external input with zod to ensure robust type safety.

Does this TypeScript convention approach work with vitest and zod?

Yes, these TypeScript conventions explicitly prescribe vitest as the test framework for colocated unit tests and zod for runtime validation, fitting projects with a standard src directory and strict typing.

How do I structure a TypeScript project with path aliases and barrel exports?

Structure your TypeScript project using a src directory, configure path aliases, and use shallow barrel exports while colocating tests and types to avoid deep barrel export anti-patterns and maintain scalability.

When should I use unknown over any in TypeScript?

You should use unknown over any in TypeScript when handling unvalidated external data, explicitly narrowing types afterward to prevent runtime errors and maintain strict type safety across your codebase.