Files
typebox/test/static/omit.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

105 lines
1.6 KiB
TypeScript

import { Expect } from './assert'
import { Type, Static } from '@alkdev/typebox'
{
const A = Type.Object({
A: Type.String(),
B: Type.String(),
C: Type.String(),
})
const T = Type.Omit(A, ['A', 'B'])
type T = Static<typeof T>
Expect(T).ToStatic<{
C: string
}>()
}
{
const A = Type.Object({
A: Type.String(),
B: Type.String(),
C: Type.String(),
})
const keys = ['A', 'B'] as const
const T = Type.Omit(A, keys)
type T = Static<typeof T>
Expect(T).ToStatic<{
C: string
}>()
}
{
const A = Type.Object({
A: Type.String(),
B: Type.String(),
C: Type.String(),
})
const B = Type.Object({
A: Type.String(),
B: Type.String(),
})
const T = Type.Omit(A, Type.KeyOf(B))
type T = Static<typeof T>
Expect(T).ToStatic<{
C: string
}>()
}
{
const A = Type.Object({ type: Type.Literal('A') })
const B = Type.Object({ type: Type.Literal('B') })
const C = Type.Object({ type: Type.Literal('C') })
const Union = Type.Union([A, B, C])
const Extended = Type.Object({
x: Type.Number(),
y: Type.Number(),
z: Type.Number(),
})
const T = Type.Intersect([Union, Extended])
Expect(T).ToStatic<
(
| {
type: 'A'
}
| {
type: 'B'
}
| {
type: 'C'
}
) & {
x: number
y: number
z: number
}
>()
const P = Type.Omit(T, ['type', 'x'])
Expect(P).ToStatic<
({} | {} | {}) & {
y: number
z: number
}
>()
const O = Type.Partial(P)
Expect(O).ToStatic<
({} | {} | {}) & {
y?: number | undefined
z?: number | undefined
}
>()
}