From a60d06ed2322a8b8f61995cf9b14d5edc62306be Mon Sep 17 00:00:00 2001 From: sinclair Date: Wed, 8 Nov 2023 00:09:16 +0900 Subject: [PATCH] Static Tests --- examples/index.ts | 50 +++++++++++++++++++++++++++++------------ test/static/partial.ts | 17 +++++++++++++- test/static/required.ts | 16 +++++++++++++ 3 files changed, 68 insertions(+), 15 deletions(-) diff --git a/examples/index.ts b/examples/index.ts index 13bf41e77..ed52156bd 100644 --- a/examples/index.ts +++ b/examples/index.ts @@ -1,18 +1,40 @@ +import { TypeSystem } from '@sinclair/typebox/system' +import { TypeCompiler } from '@sinclair/typebox/compiler' +import { Value, ValuePointer } from '@sinclair/typebox/value' +import { Type, TypeGuard, Kind, Static, TSchema } from '@sinclair/typebox' -// Todo: Investigate Union Default (initialize interior types) -// Todo: Implement Value.Clean() Tests - Done +// ----------------------------------------------------------- +// Create: Type +// ----------------------------------------------------------- -import { Type, Static } from '@sinclair/typebox'; - -export const A = Type.Object({ - a: Type.ReadonlyOptional(Type.Number()), - b: Type.Readonly(Type.Number()), - c: Type.Optional(Type.Number()), - d: Type.Number() +const T = Type.Object({ + x: Type.Number(), + y: Type.Number(), + z: Type.Number(), }) -const B = Type.Required(A) -const C = Type.Partial(A) -type A = Static -type B = Static -type C = Static \ No newline at end of file +type T = Static + +console.log(T) + +// ----------------------------------------------------------- +// Create: Value +// ----------------------------------------------------------- + +const V = Value.Create(T) + +console.log(V) + +// ----------------------------------------------------------- +// Compile: Type +// ----------------------------------------------------------- + +const C = TypeCompiler.Compile(T) + +console.log(C.Code()) + +// ----------------------------------------------------------- +// Check: Value +// ----------------------------------------------------------- + +console.log(C.Check(V)) diff --git a/test/static/partial.ts b/test/static/partial.ts index d0d075a84..f4f81b023 100644 --- a/test/static/partial.ts +++ b/test/static/partial.ts @@ -1,6 +1,6 @@ import { Expect } from './assert' import { Type, Static } from '@sinclair/typebox' - +import * as Types from '@sinclair/typebox' { const T = Type.Partial( Type.Object({ @@ -70,3 +70,18 @@ import { Type, Static } from '@sinclair/typebox' >() } } +{ + // https://github.com/sinclairzx81/typebox/issues/655 + const T = Type.Object({ + a: Type.ReadonlyOptional(Type.Number()), + b: Type.Readonly(Type.Number()), + c: Type.Optional(Type.Number()), + d: Type.Number(), + }) + const R: Types.TObject<{ + a: Types.TReadonlyOptional + b: Types.TReadonlyOptional + c: Types.TOptional + d: Types.TOptional + }> = Type.Partial(T) +} diff --git a/test/static/required.ts b/test/static/required.ts index cbf9fd4e4..a35c61f22 100644 --- a/test/static/required.ts +++ b/test/static/required.ts @@ -1,5 +1,6 @@ import { Expect } from './assert' import { Type, Static } from '@sinclair/typebox' +import * as Types from '@sinclair/typebox' { const T = Type.Required( Type.Object({ @@ -71,3 +72,18 @@ import { Type, Static } from '@sinclair/typebox' >() } } +{ + // https://github.com/sinclairzx81/typebox/issues/655 + const T = Type.Object({ + a: Type.ReadonlyOptional(Type.Number()), + b: Type.Readonly(Type.Number()), + c: Type.Optional(Type.Number()), + d: Type.Number(), + }) + const R: Types.TObject<{ + a: Types.TReadonly + b: Types.TReadonly + c: Types.TNumber + d: Types.TNumber + }> = Type.Required(T) +}