typescript

Enforce strict TypeScript typing patterns with const assertions and flat interfaces.

3|Updated Apr 5, 2023
One-click install
npx skills add https://github.com/mrp4sten/.dotfiles --skill typescript-mrp4sten
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typescript
Source: https://github.com/mrp4sten/.dotfiles/tree/main/development/IA/opencode/skill/typescript
Command: npx skills add https://github.com/mrp4sten/.dotfiles --skill typescript-mrp4sten

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

TypeScript codebases often struggle with inconsistent typing patterns, leading to runtime errors and harder maintenance. This Skill prescribes a set of proven typing best practices that promote safer, more predictable code across projects.

Core Features & Use Cases

  • Const Types Pattern: define a single source of truth for allowed values using const assertions and a mapped type.
  • Flat Interfaces: prefer top-level interfaces over inline nested object types to improve readability and refactorability.
  • Never Use any: encourage unknown/generic patterns to preserve type safety and flexibility.
  • Utility Types: leveraging Pick, Omit, Partial, Required, Readonly, Records, and Extract/Exclude to shape types.
  • Type Guards & Import Types: provide robust runtime type checks and clean type imports from modules. Use cases include building reliable domain models, APIs, and libraries that are easy to maintain and safe to evolve.

Quick Start

Refactor new TypeScript code to use const-based enums, flat interfaces, and strict utility types for safer, more maintainable code.

Frequently Asked Questions about typescript

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

FAQPage Schema
How do I enforce strict TypeScript types and patterns in my codebase?

Enforce strict TypeScript types by applying const assertions, flat interfaces, and utility types like Pick, Omit, and Readonly. This reduces runtime errors and improves maintainability across projects by prescribing consistent typing best practices.

What is the best way to avoid using any in TypeScript for type safety?

To avoid using any in TypeScript, use unknown and generic patterns to preserve type safety and flexibility. This approach ensures robust runtime type checks and maintains strict static analysis without compromising the type system.

How do I define a single source of truth for allowed values using TypeScript const assertions?

Define a single source of truth for allowed values in TypeScript by using const assertions combined with a mapped type. This const types pattern ensures predictable, immutable values while enforcing strict static analysis across your domain models.

When should I use TypeScript utility types like Pick, Omit, and Readonly?

Use TypeScript utility types like Pick, Omit, Partial, Required, and Readonly to shape existing types without duplicating definitions. They provide flexible type transformations that keep interfaces flat and improve overall code refactorability.

Does this TypeScript typing approach work for building reliable domain models and APIs?

Yes, this TypeScript typing approach works reliably for building domain models, APIs, and libraries. It uses flat interfaces and type guards to ensure safe, maintainable code evolution and provides clean type imports from modules.

Why prefer flat interfaces over inline nested object types in TypeScript?

Prefer flat TypeScript interfaces over inline nested object types to improve readability and refactorability. Top-level interfaces create clear boundaries for domain models, making static analysis and future code maintenance significantly easier.