This commit is contained in:
sinclair
2025-12-24 15:44:34 +09:00
commit 13d553220c
1047 changed files with 80931 additions and 0 deletions

42
test/static/enum.ts Normal file
View File

@@ -0,0 +1,42 @@
import { Expect } from './assert'
import { Type } from '@sinclair/typebox'
{
// expect all variants
enum E {
A,
B = 'hello',
C = 42,
}
const T = Type.Enum(E)
Expect(T).ToStatic<E.A | E.B | E.C>()
}
{
// expect all variants
const T = Type.Enum({
A: 1,
B: 2,
C: 3,
})
Expect(T).ToStatic<1 | 2 | 3>()
}
{
// expect variant overlap to reduce
const T = Type.Enum({
A: 1,
B: 2,
C: 2, // overlap
})
Expect(T).ToStatic<1 | 2>()
}
{
// expect empty enum to be string (as empty enums T[keyof T] evaluates as string)
enum E {}
const T = Type.Enum(E)
Expect(T).ToStatic<string>()
}
{
// expect empty enum to be never
const T = Type.Enum({})
Expect(T).ToStaticNever()
}