From a8f4f180bc6f02659dbdddf057e11d4a808d4ef0 Mon Sep 17 00:00:00 2001 From: sinclairzx81 Date: Fri, 21 Apr 2023 08:20:07 +0900 Subject: [PATCH] Revision 0.28.1 (#397) --- package-lock.json | 4 ++-- package.json | 2 +- src/typebox.ts | 2 +- test/static/index.ts | 1 + test/static/indexed.ts | 29 +++++++++++++++++++++++++++++ 5 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 test/static/indexed.ts diff --git a/package-lock.json b/package-lock.json index deb9afe..91b7e01 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@sinclair/typebox", - "version": "0.28.0", + "version": "0.28.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@sinclair/typebox", - "version": "0.28.0", + "version": "0.28.1", "license": "MIT", "devDependencies": { "@sinclair/hammer": "^0.17.1", diff --git a/package.json b/package.json index 2425770..e8ff854 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@sinclair/typebox", - "version": "0.28.0", + "version": "0.28.1", "description": "JSONSchema Type Builder with Static Type Resolution for TypeScript", "keywords": [ "typescript", diff --git a/src/typebox.ts b/src/typebox.ts index a76c35e..098346e 100644 --- a/src/typebox.ts +++ b/src/typebox.ts @@ -710,7 +710,7 @@ export interface TUndefined extends TSchema { // -------------------------------------------------------------------------- // prettier-ignore export type TLiteralUnionReduce[]> = - T extends [infer L, ...infer R] ? [Assert>['const'], ...TLiteralUnionReduce[]>>] : + T extends [infer L, ...infer R] ? [Assert>['const'], ...TLiteralUnionReduce[]>>] : [] // prettier-ignore export type TLiteralUnion[]>> = diff --git a/test/static/index.ts b/test/static/index.ts index 70f0034..2d551c7 100644 --- a/test/static/index.ts +++ b/test/static/index.ts @@ -10,6 +10,7 @@ import './emum' import './extract' import './exclude' import './function' +import './indexed' import './instance-type' import './intersect' import './keyof' diff --git a/test/static/indexed.ts b/test/static/indexed.ts new file mode 100644 index 0000000..7e12c01 --- /dev/null +++ b/test/static/indexed.ts @@ -0,0 +1,29 @@ +import { Expect } from './assert' +import { Type, Static } from '@sinclair/typebox' + +{ + const T = Type.Object({ + x: Type.Number(), + y: Type.String(), + }) + const I = Type.Index(T, ['x', 'y']) + Expect(I).ToInfer() +} +{ + const T = Type.Tuple([Type.Number(), Type.String(), Type.Boolean()]) + const I = Type.Index(T, Type.Union([Type.Literal('0'), Type.Literal('1')])) + Expect(I).ToInfer() +} +{ + const T = Type.Tuple([Type.Number(), Type.String(), Type.Boolean()]) + const I = Type.Index(T, Type.Union([Type.Literal(0), Type.Literal(1)])) + Expect(I).ToInfer() +} +{ + const T = Type.Object({ + ab: Type.Number(), + ac: Type.String(), + }) + const I = Type.Index(T, Type.TemplateLiteral([Type.Literal('a'), Type.Union([Type.Literal('b'), Type.Literal('c')])])) + Expect(I).ToInfer() +}