Files
typebox/docs/values/convert.md

691 B

Home | Installation | Usage | Types | Values | Syntax | TypeRegistry | TypeCheck

Convert

Use the Convert function to convert a value into its target type if a reasonable conversion is possible. This function may return an invalid value and should be checked before use. Its return type is unknown.

const T = Type.Object({ x: Type.Number() });

const R1 = Value.Convert(T, { x: "3.14" }); // const R1 = { x: 3.14 }

const R2 = Value.Convert(T, { x: "not a number" }); // const R2 = { x: 'not a number' }

Back to Home