typescript-service-patterns

Replace exceptions with explicit Result types in TypeScript business logic.

1|1|Updated Mar 22, 2026
One-click install
npx skills add https://github.com/zzafergok/skills --skill typescript-service-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typescript-service-patterns
Source: https://github.com/zzafergok/skills/tree/main/05-backend-development/typescript-service-patterns
Command: npx skills add https://github.com/zzafergok/skills --skill typescript-service-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Solve the problem of writing robust, testable business logic in TypeScript by replacing exceptions with explicit Result types.

Core Features & Use Cases

  • Result type pattern for explicit success/failure without throwing exceptions across service boundaries.
  • Typed error definitions (unions and structured errors) to improve compile-time safety and runtime clarity.
  • Layered service architecture with a pure service layer, repository pattern, and DI-friendly design, enabling framework-agnostic usage in Next.js, Node.js, or any TS project.
  • Repository pattern examples including Firestore-like implementations and mock repos for deterministic unit tests.

Quick Start

Create a small TypeScript service using Result types and a repository, and write a test that asserts correct error handling.

Frequently Asked Questions about typescript-service-patterns

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

FAQPage Schema
How do I handle errors in TypeScript without throwing exceptions?

To handle errors in TypeScript without throwing exceptions, use explicit Result<T,E> types across service boundaries. This pattern replaces try-catch blocks with structured success and failure objects, improving compile-time safety and making business logic robust and predictable.

What is the repository pattern in TypeScript service layers?

The repository pattern in TypeScript abstracts data access behind typed interfaces, allowing service layers to interact with storage like Firestore without direct coupling. This enables dependency injection and mock implementations for deterministic unit testing.

Can I use Result types with Next.js or Node.js backend services?

Yes, Result types work with Next.js, Node.js, and any TypeScript project. The service layer is framework-agnostic, using dependency injection and repository-based data access to ensure domain logic remains pure and testable across different backend environments.

How do I write testable business logic in TypeScript?

To write testable business logic in TypeScript, implement a pure service layer using dependency injection and repository patterns. By replacing exceptions with explicit Result types and using mock repositories, you achieve deterministic unit tests that verify exact error handling.

Does TypeScript Result type pattern improve compile-time safety?

The TypeScript Result type pattern improves compile-time safety by using typed error definitions and structured error unions. This forces explicit handling of failure cases at compile time, ensuring all potential errors are addressed before runtime execution.

Why should I use typed error definitions instead of standard Error objects?

Typed error definitions replace standard Error objects with structured unions to improve runtime clarity and compile-time safety. This ensures errors are explicit and predictable across service boundaries, eliminating hidden exception handling and untyped failure states.