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

43 lines
732 B
TypeScript

import { Expect } from './assert'
import { Type } from '@alkdev/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()
}