Revision 0.33.13 (#1011)

* Correctly Deref Union Variant in Default

* Version

* ChangeLog
This commit is contained in:
Haydn Paterson
2024-10-02 22:00:16 +09:00
committed by GitHub
parent 0ed2071eed
commit e5d5ec0515
11 changed files with 68 additions and 47 deletions
+36 -1
View File
@@ -1,5 +1,5 @@
import { Value } from '@sinclair/typebox/value'
import { Type } from '@sinclair/typebox'
import { TSchema, Type } from '@sinclair/typebox'
import { Assert } from '../../assert/index'
// prettier-ignore
@@ -55,4 +55,39 @@ describe('value/default/Recursive', () => {
id: 1
})
})
// ----------------------------------------------------------------
// https://github.com/sinclairzx81/typebox/issues/1010
// ----------------------------------------------------------------
it('Should default Recursive Union', () => {
const Binary = <Node extends TSchema>(node: Node) => Type.Object({
type: Type.Literal('Binary'),
left: node,
right: node
})
const Node = Type.Object({
type: Type.Literal('Node'),
value: Type.String({ default: 'X' })
})
const Expr = Type.Recursive(This => Type.Union([Binary(This), Node]))
const R = Value.Default(Expr, {
type: 'Binary',
left: {
type: 'Node'
},
right: {
type: 'Node'
}
})
Assert.IsEqual(R, {
type: 'Binary',
left: {
type: 'Node',
value: 'X'
},
right: {
type: 'Node',
value: 'X'
}
})
})
})