Skip to content

Ensuring adherence to existing TypeScript interface #449

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

You must be logged in to vote

@sdc395 Hi,

Sorry for the delay in reply on this one (I must have missed this question). TypeBox doesn't have a Describe<T> utility type built in, but it does have types to express each schematic. By convention, TypeBox types are prefixed with T, so you can enforce structures in the following way.

import { Type, TObject, TString, TNumber } from '@sinclair/typebox'

const user: TObject<{
   name: TString,
   age: TNumber
}> = Type.Object({
    name: Type.String(),
    age: Type.Number(),
})

Additionally, it's possible to implement Describe<T> through conditional mapping. The following is one way you can achieve this.

TypeScript Link Here

import { TObject, TString, TNumber, TBoolean, TUnknown 

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by sdc395
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