typescript-patterns

Enforce strict TypeScript patterns for type definitions, interfaces, generics, and type guards.

7|3|Updated Dec 24, 2023
One-click install
npx skills add https://github.com/Pony-Unicorn/react-template --skill typescript-patterns-pony-unicorn
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typescript-patterns
Source: https://github.com/Pony-Unicorn/react-template/tree/main/.agents/skills/typescript-patterns
Command: npx skills add https://github.com/Pony-Unicorn/react-template --skill typescript-patterns-pony-unicorn

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps enforce strict TypeScript patterns and best practices, preventing common anti-patterns and improving code quality and maintainability.

Core Features & Use Cases

  • Const Types: Ensures a single source of truth for string literals, improving refactoring and autocompletion.
  • Flat Interfaces: Promotes a clean, readable interface structure by avoiding inline nested objects.
  • Avoid any: Encourages the use of unknown and generics for better type safety.
  • Type Guards: Provides a clear pattern for type narrowing.
  • Use Case: When refactoring a large TypeScript codebase, use this Skill to identify and correct instances of any, inline interfaces, and non-const unions.

Quick Start

Apply the typescript-patterns skill to refactor the provided TypeScript code to adhere to strict patterns.

Frequently Asked Questions about typescript-patterns

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

FAQPage Schema
How do I remove 'any' from my TypeScript codebase to improve type safety?

To remove 'any' and improve type safety, replace it with 'unknown' and utilize generics. This enforces strict type checking and prevents runtime errors caused by untyped data.

What is the best way to enforce flat interfaces for TypeScript refactoring?

The best way to enforce flat interfaces during TypeScript refactoring is to avoid inline nested objects. This promotes a clean, readable structure and improves long-term code maintainability.

When do I need to use const types for string literals in TypeScript?

You need to use const types for string literals when establishing a single source of truth. This improves autocompletion accuracy and simplifies codebase refactoring by preventing literal drift.

How do I implement type guards for type narrowing in TypeScript?

Implement type guards by defining clear patterns to check data types at runtime. This allows TypeScript to safely narrow types, ensuring type safety when handling 'unknown' variables or complex unions.

Can I use this approach to refactor all .ts and .tsx files?

Yes, you can apply these strict TypeScript patterns to all .ts and .tsx files. This ensures code quality across your entire project during development and refactoring by enforcing type definitions and best practices.