/ * Safely parses a UINT8 into an Effect. * @template TUINT8 extends bigint * @param {TUINT8} uint8 * @returns {Effect.Effect<never, InvalidUINTError, TUINT8>} */ export const parseUINT8Safe = (uint8) => { const out = /@type {Effect.Effect<never, InvalidUINTError, TUINT8>} */ ( parseEither(SUINT8)(uint8).pipe( mapError( ({ errors: cause }) => new InvalidUINTError({ uint: /** @type bigint */ (uint8), size: 8, cause, }), ), ) ) return out }
Feels overly verbose though is there an easier way create specific validation errors? I want to throw a custom error for all 3 cases (not a big int, negative big int, overflowed)