typescript

Guides writing type-safe, idiomatic TypeScript code following modern conventions.

Updated Nov 21, 2025
One-click install
npx skills add https://github.com/alatyshau/duet --skill typescript-alatyshau
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typescript
Source: https://github.com/alatyshau/duet/tree/main/packages/skills/coding/typescript
Command: npx skills add https://github.com/alatyshau/duet --skill typescript-alatyshau

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing TypeScript that is merely valid is easy, but writing type-safe, maintainable TypeScript requires discipline. This Skill encodes proven conventions from "Effective TypeScript" and the TypeScript Handbook so generated code avoids common pitfalls like unsafe any usage, non-exhaustive switch handling, and implicit return types. ## Core Features & Use Cases - Type Safety Rules: Enforces explicit return types on exports, unknown over any, and discriminated unions for result types. - Idiomatic Patterns: Provides const assertions, exhaustive checks with never, and branded types for domain safety. - Project Conventions: Standardizes barrel exports, separate type imports, and flags anti-patterns like unjustified as assertions and enums. - Use Case: When asking an AI to implement a new service module, this Skill ensures the output uses discriminated union result types, exhaustive error handling, and clean barrel exports matching your codebase style. ## Quick Start Write a TypeScript user service with type-safe error handling following the typescript skill conventions.

Frequently Asked Questions about typescript

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

FAQPage Schema
How do I write type-safe TypeScript code?

Use explicit return types on exported functions, prefer unknown over any for unvalidated input, and model outcomes with discriminated unions. Validate unknown data with type guards before use instead of casting with as.

How to handle errors with discriminated unions in TypeScript?

Define a Result type as a union of success and error variants distinguished by a status field. Consume it with a switch statement and add a never-typed exhaustive check in the default branch so the compiler flags unhandled cases.

Should I use enums or union types in TypeScript?

Prefer string literal unions or const objects over enums. Const assertions like `as const` on an array produce literal types that are simpler, tree-shakeable, and avoid the runtime quirks of TypeScript enums.

When is using any acceptable in TypeScript?

Any is acceptable only with explicit justification, such as interfacing with untyped third-party code. In all other cases use unknown and narrow with type guards, since any silently disables type checking across the codebase.

What are branded types in TypeScript used for?

Branded types attach a unique symbol to a primitive, such as `type UserId = string & { readonly brand: unique symbol }`, preventing accidental mixing of semantically different strings like user IDs and order IDs at compile time.