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" });