@@ -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> :
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user