Skip to content

Are nested transforms executed when encoding? #672

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

You must be logged in to vote

@rolanday Hi,

This was actually a bug with Intersect transforms (these have been difficult to get right). I have published a fix on 0.31.28 which should resolve the issue. The following works on this revision.

npm install @sinclair/typebox@latest
import { Value } from '@sinclair/typebox/value'
import { Type } from '@sinclair/typebox'

const T = Type.Transform(Type.Object({ 
  isHybrid: Type.Boolean() 
}))
  .Decode((value) => ({ isHybrid: value.isHybrid ? 1 : 0 }))
  .Encode((value) => ({ isHybrid: value.isHybrid === 1 ? true : false }))

const I = Type.Intersect([
  Type.Object({ model: Type.String() }),
  Type.Object({ features: Type.Array(T) }),
])

const D = Value.Decode(I, {     // c…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@rolanday
Comment options

Answer selected by rolanday
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