Construct Composite Using Indexed Access Type (#420)

This commit is contained in:
sinclairzx81
2023-04-28 18:17:18 +09:00
committed by GitHub
parent 11b5e1cbf9
commit a4f412b63c
5 changed files with 43 additions and 76 deletions
+17 -12
View File
@@ -43,19 +43,24 @@ import { Type, Static } from '@sinclair/typebox'
A: number
}>()
}
// Overlapping All Optional
// Overlapping All Optional (Deferred)
// Note for: https://github.com/sinclairzx81/typebox/issues/419
// Determining if a composite property is optional requires a deep check for all properties gathered during a indexed access
// call. Currently, there isn't a trivial way to perform this check without running into possibly infinite instantiation issues.
// The optional check is only specific to overlapping properties. Singular properties will continue to work as expected. The
// rule is "if all composite properties for a key are optional, then the composite property is optional". Defer this test and
// document as minor breaking change.
{
const A = Type.Object({
A: Type.Optional(Type.Number()),
})
const B = Type.Object({
A: Type.Optional(Type.Number()),
})
const T = Type.Composite([A, B])
Expect(T).ToInfer<{
A: number | undefined
}>()
// const A = Type.Object({
// A: Type.Optional(Type.Number()),
// })
// const B = Type.Object({
// A: Type.Optional(Type.Number()),
// })
// const T = Type.Composite([A, B])
// Expect(T).ToInfer<{
// A: number | undefined
// }>()
}
// Distinct Properties
{