Skip to content

How to mark all fields in a type as optional. #835

Answered by sinclairzx81
dhruv-nudge asked this question in Q&A
Discussion options

You must be logged in to vote

@dhruv-nudge Hi,

TypeBox doesn't provide a built in deepPartial method (as there is no equivalent TS utility type). In TypeScript however, the expectation is generally to leverage the type system programmatically produce an appropriate mapped type. TypeBox follows a similar reasoning, but is a bit more complex as you will need to map both runtime and static type.

The following programmatically implements a PartialDeep type.

TypeScript Link Here

import { TypeGuard, Type, TSchema, TIntersect, TUnion, TObject, TPartial, TProperties, Evaluate } from '@sinclair/typebox'

// -------------------------------------------------------------------------------------
// TPartialDeepProperties
// ------…

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@dhruv-nudge
Comment options

@Dhruv-Garg79
Comment options

@darthsalad
Comment options

@sinclairzx81
Comment options

@Dhruv-Garg79
Comment options

Answer selected by dhruv-nudge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants