diff --git a/src/type/array/array.ts b/src/type/array/array.ts index 09ca326..912a5ed 100644 --- a/src/type/array/array.ts +++ b/src/type/array/array.ts @@ -26,10 +26,11 @@ THE SOFTWARE. ---------------------------------------------------------------------------*/ -import type { TSchema, SchemaOptions } from '../schema/index' +import { CloneType } from '../clone/type' +import { Ensure } from '../helpers/index' +import type { SchemaOptions, TSchema } from '../schema/index' import type { Static } from '../static/index' import { Kind } from '../symbols/index' -import { CloneType } from '../clone/type' export interface ArrayOptions extends SchemaOptions { /** The minimum number of items in this array */ @@ -45,9 +46,10 @@ export interface ArrayOptions extends SchemaOptions { /** A maximum number of contains schema matches */ maxContains?: number } +type ArrayStatic = Ensure[]> export interface TArray extends TSchema, ArrayOptions { [Kind]: 'Array' - static: Array> + static: ArrayStatic type: 'array' items: T } diff --git a/src/type/record/record.ts b/src/type/record/record.ts index 53c4011..b4ff984 100644 --- a/src/type/record/record.ts +++ b/src/type/record/record.ts @@ -181,7 +181,7 @@ function FromNumberKey(_: K, T: T, options // ------------------------------------------------------------------ // prettier-ignore type RecordStatic = ( - Evaluate, PropertyKey>, Static>> + Evaluate<{ [_ in Assert, PropertyKey>]: Static; }> ) // prettier-ignore export interface TRecord extends TSchema { diff --git a/test/static/recursive.ts b/test/static/recursive.ts index cfd5a76..c1e8bcd 100644 --- a/test/static/recursive.ts +++ b/test/static/recursive.ts @@ -1,5 +1,5 @@ +import { Static, Type } from '@sinclair/typebox' import { Expect } from './assert' -import { Type, Static } from '@sinclair/typebox' { // identity @@ -78,3 +78,24 @@ import { Type, Static } from '@sinclair/typebox' nodes: Static[] }>() } +{ + // issue: https://github.com/sinclairzx81/typebox/issues/336 + type JSONValue = + | string + | number + | null + | boolean + | { [x: string]: JSONValue } + | JSONValue[] + const R = Type.Recursive((Node) => + Type.Union([ + Type.Null(), + Type.String(), + Type.Number(), + Type.Boolean(), + Type.Record(Type.String(), Node), + Type.Array(Node), + ]), + ) + Expect(R).ToStatic() +}