Revision 0.8.14 (#24)

* Use TSyntax Types

* Version
This commit is contained in:
sinclairzx81
2025-02-06 18:57:22 +09:00
committed by GitHub
parent 01eba09e21
commit 0d5bc5a188
4 changed files with 13 additions and 16 deletions

View File

@@ -37,7 +37,7 @@ type BaseSchema = v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>
/** Statically infers a type */
// prettier-ignore
export type Static<Type extends object | string> = (
Type extends string ? s.StaticParseAsType<{}, Type> :
Type extends string ? s.TSyntax<{}, Type> :
Type extends Validator<infer Type extends t.TSchema> ? t.Static<Type> :
Type extends t.TSchema ? t.Static<Type> :
Type extends BaseSchema ? v.InferInput<Type> :

View File

@@ -26,7 +26,7 @@ THE SOFTWARE.
---------------------------------------------------------------------------*/
import { StaticParseAsSchema, Parse } from '@sinclair/typebox/syntax'
import { TSyntax, Syntax } from '@sinclair/typebox/syntax'
import * as t from '@sinclair/typebox'
// ------------------------------------------------------------------
@@ -35,13 +35,10 @@ import * as t from '@sinclair/typebox'
// prettier-ignore
export type TTypeBoxFromSyntax<Context extends t.TProperties, Type extends string,
TypeBox = StaticParseAsSchema<Context, Type>,
Result extends t.TSchema = TypeBox extends t.TSchema ? TypeBox : t.TNever
Result extends t.TSchema = TSyntax<Context, Type>
> = Result
/** Creates a TypeBox Type From Syntax */
export function TypeBoxFromSyntax<Context extends t.TProperties, Type extends string>(context: Context, type: Type, options?: t.SchemaOptions): TTypeBoxFromSyntax<Context, Type> {
const typebox = t.ValueGuard.IsString(type) ? Parse(context, type, options) : t.Never()
const result = t.KindGuard.IsSchema(typebox) ? typebox : t.Never()
return result as never
return Syntax(context, type, options)
}