Skip to main content

createErrorFactory()

createErrorFactory<Code>(errorType): (code, details?) => CodedError

Creates a factory function for generating CodedError instances of a specific type. The factory is tree-shakable: if not imported, it won't be bundled.


Type Parameters​

Code: Code extends number​

The numeric error codes allowed for this factory.


Parameters​

errorType: string​

The error type/category (e.g., "Animation", "Semaphore").


Returns​

A factory function that creates CodedError instances.


Since​

2.0.0


Example​

const createAnimationError = createErrorFactory<100 | 101 | 102>("Animation");
throw createAnimationError(101, { id: "missing" });