mirror of
https://github.com/zoriya/typebox.git
synced 2026-05-27 00:26:52 +00:00
Revision 0.28.1 (#397)
This commit is contained in:
@@ -10,6 +10,7 @@ import './emum'
|
||||
import './extract'
|
||||
import './exclude'
|
||||
import './function'
|
||||
import './indexed'
|
||||
import './instance-type'
|
||||
import './intersect'
|
||||
import './keyof'
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import { Expect } from './assert'
|
||||
import { Type, Static } from '@sinclair/typebox'
|
||||
|
||||
{
|
||||
const T = Type.Object({
|
||||
x: Type.Number(),
|
||||
y: Type.String(),
|
||||
})
|
||||
const I = Type.Index(T, ['x', 'y'])
|
||||
Expect(I).ToInfer<number | string>()
|
||||
}
|
||||
{
|
||||
const T = Type.Tuple([Type.Number(), Type.String(), Type.Boolean()])
|
||||
const I = Type.Index(T, Type.Union([Type.Literal('0'), Type.Literal('1')]))
|
||||
Expect(I).ToInfer<number | string>()
|
||||
}
|
||||
{
|
||||
const T = Type.Tuple([Type.Number(), Type.String(), Type.Boolean()])
|
||||
const I = Type.Index(T, Type.Union([Type.Literal(0), Type.Literal(1)]))
|
||||
Expect(I).ToInfer<number | string>()
|
||||
}
|
||||
{
|
||||
const T = Type.Object({
|
||||
ab: Type.Number(),
|
||||
ac: Type.String(),
|
||||
})
|
||||
const I = Type.Index(T, Type.TemplateLiteral([Type.Literal('a'), Type.Union([Type.Literal('b'), Type.Literal('c')])]))
|
||||
Expect(I).ToInfer<number | string>()
|
||||
}
|
||||
Reference in New Issue
Block a user