From da10cc09fa4adc159dccaaac9d6ff038f970c1e6 Mon Sep 17 00:00:00 2001 From: sinclairzx81 Date: Tue, 4 Jul 2023 07:27:22 +0900 Subject: [PATCH] Revision 0.29.3 (#487) --- package.json | 2 +- src/typebox.ts | 4 ++-- test/static/keyof.ts | 9 +++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 2b017e2..2971f5b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@sinclair/typebox", - "version": "0.29.2", + "version": "0.29.3", "description": "JSONSchema Type Builder with Static Type Resolution for TypeScript", "keywords": [ "typescript", diff --git a/src/typebox.ts b/src/typebox.ts index 5d8c046..f67705d 100644 --- a/src/typebox.ts +++ b/src/typebox.ts @@ -393,9 +393,9 @@ export interface TIntersect extends TSchema, In // TKeyOf // -------------------------------------------------------------------------- // prettier-ignore -export type TKeyOfProperties = Static extends infer S +export type TKeyOfProperties = Discard extends infer S ? UnionToTuple<{[K in keyof S]: TLiteral>}[keyof S]> - : [] + : [], undefined> // note: optional properties produce undefined types in tuple result. discard. // prettier-ignore export type TKeyOfIndicesArray = UnionToTuple // prettier-ignore diff --git a/test/static/keyof.ts b/test/static/keyof.ts index bda75e8..e5ad39f 100644 --- a/test/static/keyof.ts +++ b/test/static/keyof.ts @@ -91,3 +91,12 @@ import { Type } from '@sinclair/typebox' const K = Type.KeyOf(T) Expect(K).ToInfer<'a' | 'b' | 'c' | 'd'>() } +{ + const T = Type.Object({ + a: Type.Optional(Type.String()), + b: Type.Optional(Type.String()), + c: Type.Optional(Type.String()), + }) + const K = Type.KeyOf(T) + Expect(K).ToInfer<'a' | 'b' | 'c'>() +}