Revision 0.34.46 (#4)
* Functions Must Support TObject as Generic Constraint * ChangeLog * Version
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { Expect } from './assert'
|
||||
import { Type } from '@sinclair/typebox'
|
||||
|
||||
import { Expect, IsExtendsMutual } from './assert'
|
||||
import { Type, type TObject, type Static, type TNumber } from '@sinclair/typebox'
|
||||
{
|
||||
const T = Type.Object({
|
||||
A: Type.String(),
|
||||
@@ -68,3 +67,65 @@ import { Type } from '@sinclair/typebox'
|
||||
C: number
|
||||
}>()
|
||||
}
|
||||
// ------------------------------------------------------------------
|
||||
// Required
|
||||
// ------------------------------------------------------------------
|
||||
{
|
||||
const _A = Type.Object({})
|
||||
const _B = Type.Object({ x: Type.Number() })
|
||||
const _C = Type.Object({ x: Type.Number(), y: Type.Number() })
|
||||
|
||||
type A = (typeof _A)['required']
|
||||
type B = (typeof _B)['required']
|
||||
type C = (typeof _C)['required']
|
||||
|
||||
IsExtendsMutual<A, string[] | undefined>(true)
|
||||
IsExtendsMutual<B, ['x']>(true)
|
||||
IsExtendsMutual<C, ['x', 'y']>(true)
|
||||
}
|
||||
// ------------------------------------------------------------------
|
||||
// https://github.com/sinclairzx81/typebox/issues/1500
|
||||
// ------------------------------------------------------------------
|
||||
{
|
||||
function test<Type extends TObject>(type: Type): Static<Type> {
|
||||
return null as never
|
||||
}
|
||||
const _A = test(Type.Object({}))
|
||||
const _B = test(
|
||||
Type.Object({
|
||||
x: Type.Number(),
|
||||
y: Type.Number(),
|
||||
}),
|
||||
)
|
||||
const _C = test(
|
||||
Type.Partial(
|
||||
Type.Object({
|
||||
x: Type.Number(),
|
||||
y: Type.Number(),
|
||||
}),
|
||||
),
|
||||
)
|
||||
}
|
||||
// ------------------------------------------------------------------
|
||||
// Inference
|
||||
// ------------------------------------------------------------------
|
||||
{
|
||||
type T = Static<typeof T>
|
||||
const T = null as never as TObject<{}>
|
||||
Expect(T).ToStatic<{}>()
|
||||
}
|
||||
{
|
||||
type T = Static<typeof T>
|
||||
const T = null as never as TObject
|
||||
Expect(T).ToStatic<{
|
||||
[x: string]: unknown
|
||||
[x: number]: unknown
|
||||
}>()
|
||||
}
|
||||
{
|
||||
type T = Static<typeof T>
|
||||
const T = null as never as TObject<{ x: TNumber }>
|
||||
Expect(T).ToStatic<{
|
||||
x: number
|
||||
}>()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user