typescript

Enforce TypeScript best practices with const types, flat interfaces, and type guards.

Updated Jun 22, 2024
One-click install
npx skills add https://github.com/KilloconQ/dotfiles --skill typescript-killoconq
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typescript
Source: https://github.com/KilloconQ/dotfiles/tree/main/opencode/.config/opencode/skills/typescript
Command: npx skills add https://github.com/KilloconQ/dotfiles --skill typescript-killoconq

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Type-safe coding patterns reduce runtime errors and simplify maintenance by enforcing consistent TypeScript practices.

Core Features & Use Cases

  • Const Types Pattern: Create const objects first, then derive types to ensure a single source of truth and runtime values that aid autocomplete and refactoring.
  • Flat Interfaces: Favor flat interfaces with referenced sub-interfaces to avoid inline nesting and improve reusability.
  • Never Use any: Encourage unknown and generics to improve type safety and flexible APIs.
  • Utility Types: Demonstrates common utility types like Pick, Omit, Partial, Required, Readonly, Record, and ReturnType.
  • Type Guards & Import Types: Use type guards to narrow values and import types for clear dependencies.

Quick Start

Refactor a TypeScript codebase to implement const-backed types, flat interfaces, and safe usage of unknown and utility types.

Frequently Asked Questions about typescript

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

FAQPage Schema
How do I enforce TypeScript best practices to reduce runtime errors?

Enforce TypeScript best practices by adopting const-backed types, flat interfaces, and safe handling of unknown values. This approach reduces runtime errors by ensuring a single source of truth for definitions and strictly avoiding the any type.

What is the best way to structure TypeScript interfaces for reusability?

The best way to structure TypeScript interfaces for reusability is to favor flat interfaces with referenced sub-interfaces. This avoids inline nesting, improves code maintainability, and allows individual sub-interfaces to be reused across different modules.

How do I handle unknown values safely instead of using any in TypeScript?

Handle unknown values safely in TypeScript by replacing any with unknown and applying type guards. Type guards narrow values at runtime to ensure type safety, while generics provide flexible APIs without sacrificing strict typing constraints.

When do I need utility types like Pick and Omit in a TypeScript codebase?

You need utility types like Pick, Omit, Partial, and Record in a TypeScript codebase to transform existing types into new variants. They enable flexible type definitions without code duplication, allowing you to create required, readonly, or partial structures.

How do I refactor an existing TypeScript project to use strict type patterns?

Refactor an existing TypeScript project by creating const objects first to derive types, flattening nested interfaces, and replacing any with unknown. Apply type guards and import types for clear dependencies to achieve a strict, maintainable codebase.

Why use const-backed types as a single source of truth in TypeScript?

Use const-backed types in TypeScript to establish a single source of truth that provides both runtime values and type definitions. This pattern improves autocomplete, simplifies refactoring, and ensures your runtime values remain strictly aligned with your type definitions.