mirror of
https://github.com/zoriya/typebox.git
synced 2026-06-01 02:28:24 +00:00
Support Enum Inference In Template Literal (#445)
This commit is contained in:
+10
-8
@@ -1,12 +1,14 @@
|
||||
import { Expect } from './assert'
|
||||
import { Type, Static } from '@sinclair/typebox'
|
||||
|
||||
enum E {
|
||||
A,
|
||||
B = 'hello',
|
||||
C = 42,
|
||||
{
|
||||
enum E {
|
||||
A,
|
||||
B = 'hello',
|
||||
C = 42,
|
||||
}
|
||||
|
||||
const T = Type.Enum(E)
|
||||
|
||||
Expect(T).ToBe<Static<typeof T>>() // ?
|
||||
}
|
||||
|
||||
const T = Type.Enum(E)
|
||||
|
||||
Expect(T).ToBe<Static<typeof T>>() // ?
|
||||
|
||||
@@ -42,3 +42,31 @@ import { Type } from '@sinclair/typebox'
|
||||
const T = Type.TemplateLiteral([Type.Boolean()])
|
||||
Expect(T).ToInfer<`${boolean}`>()
|
||||
}
|
||||
{
|
||||
// Enum Implicit
|
||||
enum E {
|
||||
A,
|
||||
B,
|
||||
C,
|
||||
}
|
||||
const A = Type.Enum(E)
|
||||
const T = Type.TemplateLiteral([Type.Literal('hello'), A])
|
||||
Expect(T).ToInfer<'hello0' | 'hello1' | 'hello2'>()
|
||||
}
|
||||
{
|
||||
// Enum Explicit
|
||||
enum E {
|
||||
A,
|
||||
B = 'B',
|
||||
C = 'C',
|
||||
}
|
||||
const A = Type.Enum(E)
|
||||
const T = Type.TemplateLiteral([Type.Literal('hello'), A])
|
||||
Expect(T).ToInfer<'hello0' | 'helloB' | 'helloC'>()
|
||||
}
|
||||
{
|
||||
// Enum Object Explicit
|
||||
const A = Type.Enum(Object.freeze({ a: 'A', b: 'B' }))
|
||||
const T = Type.TemplateLiteral([Type.Literal('hello'), A])
|
||||
Expect(T).ToInfer<'helloA' | 'helloB'>()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user