typescript-style

Guides writing, designing, and reviewing strict TypeScript with opinionated rules and references.

2|Updated Apr 2, 2026
One-click install
npx skills add https://github.com/nseng-ai/ns --skill typescript-style-nseng-ai
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typescript-style
Source: https://github.com/nseng-ai/ns/tree/main/skills/internal/typescript/typescript-style
Command: npx skills add https://github.com/nseng-ai/ns --skill typescript-style-nseng-ai

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? TypeScript codebases drift into inconsistent patterns: enums mixed with unions, any leaking through boundaries, exceptions thrown for expected failures, and abstractions larger than the problems they solve. This Skill provides a single opinionated style guide so agents and developers write, design, and review strict, portable TypeScript consistently. ## Core Features & Use Cases - Core rules and idioms: Covers erasable TypeScript, string-literal and discriminated unions, Zod boundary validation, errors-as-values with Result<T,E>, dependency injection, and naming conventions, with copy-paste-ready code patterns. - Pre-finish checklist: A structured rubric for language, types, architecture, errors, and hygiene to run before declaring implementation or review work done. - Deep references and case studies: Conditional-loading guides for backend-neutral abstractions, stateful workflow loops, plugin/extension systems, terminal UIs, error handling, and review taste. - Use Case: When reviewing a PR that scatters if (backend.includes("x")) checks and throws on validation failures, load this Skill to get concrete review wording and the correct patterns: capability flags resolved once, and expected failures returned as typed values. ## Quick Start Ask the agent to review your TypeScript module against the typescript-style guide and apply its core rules and checklist before finishing.

Frequently Asked Questions about typescript-style

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

FAQPage Schema
How do I write strict TypeScript without enums and namespaces?

Use string-literal unions for closed sets and discriminated unions for runtime variants, keeping code erasable so types strip without changing runtime behavior. Derive runtime lists and static types from one `as const` array when both are needed.

How should TypeScript handle expected errors at async boundaries?

Return expected failures as values using `Result<T,E>` or terminal error events in streams, reserving `throw` for programmer errors and broken invariants. Thread `AbortSignal` through long-running work and represent cancellation distinctly from failure.

Should I use interface or type in TypeScript?

Use `interface` for object shapes and contracts, and `type` for unions, function aliases, conditional types, and mapped types. An empty `interface X extends Y {}` should be written as `type X = Y` unless it adds real members.

Does this TypeScript style guide work with Zod validation?

Yes, Zod is the default runtime validation library for external boundaries. Parse untyped input with schemas declared via `z.lazy`, use `z.looseObject` for unknown-key-preserving objects, and derive static types with `z.infer` instead of hand-written mirror types.

When should I not apply this TypeScript style guide?

Project instructions, tooling, and existing conventions take precedence; do not churn code with style-only rewrites. Apply the guide to new or touched code, and keep public API compatibility unless the task explicitly asks to break it.