Skillquality 0.46

functional-ts

Use when writing server-side TypeScript code involving domain models, use cases, repositories, state transitions, or business logic. Guides functional domain modeling with discriminated unions, pure functions, and Result types.

Price
free
Protocol
skill
Verified
no

What it does

Functional Domain Modeling in TypeScript

Principles for writing domain models in server-side TypeScript. Instead of class-based OOP, this approach maximizes the TypeScript type system through a functional style.

1. Type-Driven Domain Modeling

Represent states with discriminated unions using kind as the unified discriminant. Use type (not interface), companion objects, branded types, Readonly<>, function property notation, and one-concept-per-file structure.

Validation library detection: Check dependencies / devDependencies in the project's package.json for branded type syntax:

Details: domain-modeling.md

2. State Transitions via Functions

Express state transitions with pure functions. The argument type constrains valid source states, and the return type makes the target state explicit. Invalid transitions become compile errors. Use assertNever for exhaustiveness checking.

Details: state-modeling.md

3. Error Handling — Railway Oriented Programming

Do not throw exceptions; treat errors as values using the Result type. Define error types as discriminated unions so callers can handle them exhaustively.

Library detection: Check dependencies / devDependencies in the project's package.json:

Details: error-handling.md

4. Boundary Defense

Validate external inputs (API requests, DB results, file reads) with validation library schemas at runtime. Trust types inside the domain layer. Do not use type assertions (as). Apply Sensitive<T> wrapper to PII fields.

Details: boundary-defense.md

5. Declarative Style

Write array transformations declaratively using filter / map / reduce with companion object predicates. Model domain events as immutable records.

Details: declarative-style.md

6. Test Data

Define test data with as const satisfies Type to preserve discriminant literal types and prevent widening.

Details: test-data.md

Applying These Principles

These are recommendations, not strict rules. You may use your judgment based on context, but if you deviate from a principle, explicitly state the reason in a comment.

Typical justified reasons to deviate:

  • An external library requires class inheritance
  • Immutable object creation cost is a performance concern
  • A different pattern has been adopted by team agreement

Capabilities

skillsource-iwasa-kosuiskill-functional-tstopic-agent-skills

Install

Installnpx skills add iwasa-kosui/functional-ts-principles
Transportskills-sh
Protocolskill

Quality

0.46/ 1.00

deterministic score 0.46 from registry signals: · indexed on github topic:agent-skills · 17 github stars · SKILL.md body (3,009 chars)

Provenance

Indexed fromgithub
Enriched2026-05-10 07:03:40Z · deterministic:skill-github:v1 · v1
First seen2026-05-10
Last seen2026-05-10

Agent access