Revision 0.32.17 (#799)

* Detect Any on StaticDecode

* Revision 0.32.17
This commit is contained in:
sinclairzx81
2024-03-20 18:45:53 +09:00
committed by GitHub
parent 9fa2e2801c
commit ec27004427
4 changed files with 16 additions and 4 deletions
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "@sinclair/typebox",
"version": "0.32.16",
"version": "0.32.17",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@sinclair/typebox",
"version": "0.32.16",
"version": "0.32.17",
"license": "MIT",
"devDependencies": {
"@arethetypeswrong/cli": "^0.13.2",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@sinclair/typebox",
"version": "0.32.16",
"version": "0.32.17",
"description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
"keywords": [
"typescript",
+2 -1
View File
@@ -85,8 +85,9 @@ export type TDecodeType<T extends TSchema> = (
// ------------------------------------------------------------------
// Static
// ------------------------------------------------------------------
export type StaticDecodeIsAny<T> = boolean extends (T extends TSchema ? true : false) ? true : false
/** Creates an decoded static type from a TypeBox type */
export type StaticDecode<T extends TSchema, P extends unknown[] = []> = Static<TDecodeType<T>, P>
export type StaticDecode<T extends TSchema, P extends unknown[] = []> = StaticDecodeIsAny<T> extends true ? unknown : Static<TDecodeType<T>, P>
/** Creates an encoded static type from a TypeBox type */
export type StaticEncode<T extends TSchema, P extends unknown[] = []> = Static<T, P>
/** Creates a static type from a TypeBox type */
+11
View File
@@ -1,4 +1,7 @@
import { Type, TSchema, Static, StaticDecode, TObject, TNumber } from '@sinclair/typebox'
import { TypeCheck } from '@sinclair/typebox/compiler'
import { Value } from '@sinclair/typebox/value'
import { Expect } from './assert'
{
// string > number
@@ -309,3 +312,11 @@ import { Expect } from './assert'
Expect(T).ToStaticDecode<new (x: Date) => Date>()
Expect(T).ToStaticEncode<new (x: number) => number>()
}
// -------------------------------------------------------------
// https://github.com/sinclairzx81/typebox/issues/798
// -------------------------------------------------------------
{
const c1: TypeCheck<any> = {} as any
const x1 = c1.Decode({})
const x2 = Value.Decode({} as any, {})
}