mirror of
https://github.com/zoriya/typebox.git
synced 2026-05-28 17:06:41 +00:00
Composite Evaluate (#349)
This commit is contained in:
@@ -1,19 +1,74 @@
|
||||
import { Expect } from './assert'
|
||||
import { Type } from '@sinclair/typebox'
|
||||
import { Type, Static } from '@sinclair/typebox'
|
||||
|
||||
// Overlapping - Non Varying
|
||||
{
|
||||
const A = Type.Object({
|
||||
A: Type.String(),
|
||||
B: Type.String(),
|
||||
A: Type.Number(),
|
||||
})
|
||||
const B = Type.Object({
|
||||
A: Type.Number(),
|
||||
})
|
||||
const T = Type.Composite([A, B])
|
||||
|
||||
Expect(T).ToInfer<{
|
||||
A: number
|
||||
}>()
|
||||
}
|
||||
// Overlapping - Varying
|
||||
{
|
||||
const A = Type.Object({
|
||||
A: Type.Number(),
|
||||
})
|
||||
const B = Type.Object({
|
||||
A: Type.String(),
|
||||
})
|
||||
const T = Type.Composite([A, B])
|
||||
|
||||
Expect(T).ToInfer<{
|
||||
A: never
|
||||
}>()
|
||||
}
|
||||
// Overlapping Single Optional
|
||||
{
|
||||
const A = Type.Object({
|
||||
A: Type.Optional(Type.Number()),
|
||||
})
|
||||
const B = Type.Object({
|
||||
A: Type.Number(),
|
||||
})
|
||||
const T = Type.Composite([A, B])
|
||||
|
||||
Expect(T).ToInfer<{
|
||||
A: number
|
||||
}>()
|
||||
}
|
||||
// Overlapping All Optional
|
||||
{
|
||||
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
|
||||
{
|
||||
const A = Type.Object({
|
||||
A: Type.Number(),
|
||||
})
|
||||
const B = Type.Object({
|
||||
B: Type.Number(),
|
||||
})
|
||||
const T = Type.Composite([A, B])
|
||||
|
||||
Expect(T).ToInfer<{
|
||||
A: string | number
|
||||
B: string | number
|
||||
A: number
|
||||
B: number
|
||||
}>()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user