Files
typebox/test/static/rest.ts
glm-5.1 bd758c2342 Fork from @sinclair/typebox 0.34.49 as @alkdev/typebox
- Rename package from @sinclair/typebox to @alkdev/typebox
- Update author, repository, and homepage to alkdev
- Remove GitHub workflows, .vscode config, and branding assets
- Update all source, test, example, changelog, and task imports
- Update tsconfig.json path mappings
- Clean up readme header (remove upstream badges/branding)
2026-04-23 13:22:31 +00:00

53 lines
1.2 KiB
TypeScript

import { Expect } from './assert'
import { Type, Static } from '@alkdev/typebox'
{
// union never
const A = Type.String()
const B = Type.Union(Type.Rest(A))
Expect(B).ToStaticNever()
}
{
// intersect never
const A = Type.String()
const B = Type.Intersect(Type.Rest(A))
Expect(B).ToStaticNever()
}
{
// tuple
const A = Type.Tuple([Type.Number(), Type.String()])
const B = Type.Union(Type.Rest(A))
Expect(B).ToStatic<string | number>()
}
{
// tuple spread
const A = Type.Tuple([Type.Literal(1), Type.Literal(2)])
const B = Type.Tuple([Type.Literal(3), Type.Literal(4)])
const C = Type.Tuple([...Type.Rest(A), ...Type.Rest(B)])
Expect(C).ToStatic<[1, 2, 3, 4]>()
}
{
// union to intersect
const A = Type.Object({ x: Type.Number() })
const B = Type.Object({ y: Type.String() })
const C = Type.Union([A, B])
const D = Type.Intersect(Type.Rest(C))
Expect(D).ToStatic<
{
x: number
} & {
y: string
}
>()
}
{
// intersect to composite
const A = Type.Object({ x: Type.Number() })
const B = Type.Object({ y: Type.String() })
const C = Type.Intersect([A, B])
const D = Type.Composite(Type.Rest(C))
Expect(D).ToStatic<{
x: number
y: string
}>()
}