Install any skill in seconds. Free to start, no credit card required.
Get Started Free →zzafergok/typescript-service-patterns
TypeScript service layer architecture with Result types, typed error definitions, and domain service patterns.
Passed 21 of 22 test cases with the skill, and 15 of 22 without it.
and 6 more in the full report
7 fixed14 passed either way0 still failing1 broke
Tokens, turns and time describe resource use, not a dollar price.
This benchmark measured an earlier version of the skill.
One of 7 test cases the skill fixed. Same model, same prompt, with and without the skill.
I need to design a TypeScript user profile service that doesn't rely on throwing exceptions for expected business errors. Can you show me how to structure a framework-agnostic domain service class that uses dependency injection for its data persistence, returns explicit success or failure container types instead of throwing runtime exceptions, and uses a union of string literals for domain error codes?
| Checked | Without skill | With skill |
|---|---|---|
| The container type uses ok: true and ok: false as the object discriminant property. | Passed | Passed |
| The domain service accepts the persistence dependency in its constructor parameters. | Passed | Passed |
| The persistence interface methods return promises resolving to Result container types. | Missed | Passed |
The instructions your model reads when the skill loads.
Production-ready patterns for type-safe error handling and domain service architecture. Framework-agnostic — usable in Next.js, Node.js, and any project that supports TypeScript.
Return the success or error state explicitly instead of throwing exceptions.
type Result<T, E = Error> = { ok: true; value: T } | { ok: false; error: E }
const Ok = <T>(value: T): Result<T, never> => ({ ok: true, value })
const Err = <E>(error: E): Result<never, E> => ({ ok: false, error })
// ❌ Exception-based — the error state is not visible in the type system
async function fetchUser(id: string): Promise<User> {
const user = await db.findById(id)
if (!user) throw new Error('Not found') // The caller does not know this
return user
}
// ✅ Result-based — the error state is visible in the signature
async function fetchUser(id: string): Promise<Result<User, 'NOT_FOUND' | 'DB_ERROR'>> {
try {
const user = await db.findById(id)
if (!user) return Err('NOT_FOUND')
return Ok(user)
} catch {
return Err('DB_ERROR')
}
}
// The caller must handle both states
const result = await fetchUser('123')
test cases passed, vs 15 / 22 without
More skills from the same source and nearby in the registry, with their headline benchmark lift.