Files
typebox/docs/values/decode-encode.md

949 B

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

Decode / Encode

Decode

Use the Decode function to decode a value from a type or throw if the value is invalid. The return value will infer as the decoded type. This function will run Transform codecs if available.

const A = Value.Decode(Type.String(), "hello"); // const A = 'hello'

const B = Value.Decode(Type.String(), 42); // throw

Encode

Use the Encode function to encode a value to a type or throw if the value is invalid. The return value will infer as the encoded type. This function will run Transform codecs if available.

const A = Value.Encode(Type.String(), "hello"); // const A = 'hello'

const B = Value.Encode(Type.String(), 42); // throw

Back to Home