Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revision 0.32.17 #799

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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, {})
}