Skip to content

Curiosity, what's the internal type Ensure<T> for? #949

Answered by sinclairzx81
castarco asked this question in Q&A
Discussion options

You must be logged in to vote

@castarco Hi,

TypeBox has two internal static evaluation types. Evaluate and Ensure. Ill try explain them a bit below.

Evaluate

The Evaluate type (sometimes called Prettify) is used to produce a clean object type, usually after intersection. TypeBox uses the term Evaluate because the mapping actually causes TypeScript to evaluate a type as a normalized distributed union. Consider the following.

TypeScript Link Here

import { Evaluate } from '@sinclair/typebox'

type T = Evaluate<({            // type T = {
  a: number                     //    a: number;
} | {                           //    c: number;
  b: number                     // } | {
}) & {                          //    b: number;

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by castarco
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants