mirror of
https://github.com/zoriya/typebox.git
synced 2026-06-01 18:45:32 +00:00
Revision 0.31.10 (#573)
* Union, Intersect and Tuple Decode Rest * Version * Transform Tests
This commit is contained in:
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@sinclair/typebox",
|
||||
"version": "0.31.9",
|
||||
"version": "0.31.10",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@sinclair/typebox",
|
||||
"version": "0.31.9",
|
||||
"version": "0.31.10",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@sinclair/hammer": "^0.17.1",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@sinclair/typebox",
|
||||
"version": "0.31.9",
|
||||
"version": "0.31.10",
|
||||
"description": "JSONSchema Type Builder with Static Type Resolution for TypeScript",
|
||||
"keywords": [
|
||||
"typescript",
|
||||
|
||||
+3
-3
@@ -868,7 +868,7 @@ export type DecodeType<T extends TSchema> = (
|
||||
T extends TAsyncIterator<infer S extends TSchema> ? TAsyncIterator<DecodeType<S>> :
|
||||
T extends TConstructor<infer P extends TSchema[], infer R extends TSchema> ? TConstructor<P, DecodeType<R>> :
|
||||
T extends TFunction<infer P extends TSchema[], infer R extends TSchema> ? TFunction<P, DecodeType<R>> :
|
||||
T extends TIntersect<infer S extends TSchema[]> ? TIntersect<S> :
|
||||
T extends TIntersect<infer S extends TSchema[]> ? TIntersect<DecodeRest<S>> :
|
||||
T extends TIterator<infer S extends TSchema> ? TIterator<DecodeType<S>> :
|
||||
T extends TNot<infer S extends TSchema> ? TNot<DecodeType<S>> :
|
||||
T extends TObject<infer S> ? TObject<Evaluate<DecodeProperties<S>>> :
|
||||
@@ -876,8 +876,8 @@ export type DecodeType<T extends TSchema> = (
|
||||
T extends TRecord<infer K, infer S> ? TRecord<K, DecodeType<S>> :
|
||||
T extends TRecursive<infer S extends TSchema> ? TRecursive<DecodeType<S>> :
|
||||
T extends TRef<infer S extends TSchema> ? TRef<DecodeType<S>> :
|
||||
T extends TTuple<infer S extends TSchema[]> ? TTuple<S> :
|
||||
T extends TUnion<infer S extends TSchema[]> ? TUnion<S> :
|
||||
T extends TTuple<infer S extends TSchema[]> ? TTuple<DecodeRest<S>> :
|
||||
T extends TUnion<infer S extends TSchema[]> ? TUnion<DecodeRest<S>> :
|
||||
T
|
||||
)
|
||||
export type TransformFunction<T = any, U = any> = (value: T) => U
|
||||
|
||||
@@ -251,3 +251,30 @@ import { Expect } from './assert'
|
||||
})
|
||||
Expect(T).ToStaticDecode<{ x: { y: string }[] }>()
|
||||
}
|
||||
{
|
||||
// should decode generic union
|
||||
const GenericUnion = <T extends TSchema>(t: T) => Type.Union([t, Type.Null()])
|
||||
const T = Type.Transform(Type.String())
|
||||
.Decode((value) => new Date(value))
|
||||
.Encode((value) => value.toISOString())
|
||||
Expect(T).ToStaticDecode<Date>()
|
||||
Expect(GenericUnion(T)).ToStaticDecode<Date | null>()
|
||||
}
|
||||
{
|
||||
// should decode generic tuple
|
||||
const GenericTuple = <T extends TSchema>(t: T) => Type.Tuple([t, Type.Null()])
|
||||
const T = Type.Transform(Type.String())
|
||||
.Decode((value) => new Date(value))
|
||||
.Encode((value) => value.toISOString())
|
||||
Expect(T).ToStaticDecode<Date>()
|
||||
Expect(GenericTuple(T)).ToStaticDecode<[Date, null]>()
|
||||
}
|
||||
{
|
||||
// should decode generic intersect
|
||||
const GenericIntersect = <T extends TSchema>(t: T) => Type.Intersect([t, Type.Literal(1)])
|
||||
const T = Type.Transform(Type.Number())
|
||||
.Decode((value) => value)
|
||||
.Encode((value) => value)
|
||||
Expect(T).ToStaticDecode<number>()
|
||||
Expect(GenericIntersect(T)).ToStaticDecode<1>()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user