Skip to content

Correctly infer type with transform and composite? #1241

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

You must be logged in to vote

@m1212e Hiya,

Since I actually want to merge two schemas into one I added two transform types to intersect and receive

Ah right. I think the only way to really achieve this to apply the Transform to the composited type. The issue is that Composite only merges the properties of each sub type, and ignores the transform and other constraints applied for each sub type. The return type for Composite is a brand new Object, so any constraints and transforms need to be re-applied.

A refactor of the types is probably the best way forward.

import { Type, StaticDecode, StaticEncode} from '@sinclair/typebox'

const A = Type.Object({ a: Type.Number() })
const B = Type.Object({ b: Type.Number() })
const

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@m1212e
Comment options

@sinclairzx81
Comment options

Answer selected by m1212e
@m1212e
Comment options

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