Turn a type guard into a validator
The validated type
The guard to convert
The failure explanation if invalid
const guard = (input): input is number => typeof input === "number" && !isNaN(input); const isNumber = fromGuard(guard, "Not a number"); isNumber(1) >> { valid: true, parsed: 1, }; Copy
const guard = (input): input is number => typeof input === "number" && !isNaN(input); const isNumber = fromGuard(guard, "Not a number"); isNumber(1) >> { valid: true, parsed: 1, };
Turn a type guard into a validator