Skip to content

Commit

Permalink
Revision 0.32.17 (#799)
Browse files Browse the repository at this point in the history
* Detect Any on StaticDecode

* Revision 0.32.17
  • Loading branch information
sinclairzx81 committed Mar 20, 2024
1 parent 9fa2e28 commit ec27004
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/type/static/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
11 changes: 11 additions & 0 deletions test/static/transform.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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, {})
}

0 comments on commit ec27004

Please sign in to comment.