Function: validateAndConvert()
function validateAndConvert<T>(
value: unknown,
validator: (val: unknown) => val is T,
errorMessage?: string
): T;
Defined in: shared/utils/typeHelpers.ts:213
Type-safe conversion from unknown to a specific type with validation.
Type Parametersโ
Tโ
T
Parametersโ
valueโ
unknown
Unknown value to convert
validatorโ
(val: unknown) => val is T
Validation function that returns true if value is of type T
errorMessage?โ
string
Returnsโ
T
Validated value of type T
Remarksโ
Use this instead of direct type assertions when you can validate the type. Provides runtime safety in addition to compile-time types.
Throwsโ
Error if validation fails