From 5cc7cb5e2b8a1de0592dd8c3506adc6d1f0b2447 Mon Sep 17 00:00:00 2001 From: Ruben Grimm Date: Wed, 21 Feb 2024 09:53:44 +0100 Subject: [PATCH] Fix: Copy array/tuple-logic from DelimiterCasedPropertiesDeep to CamelCasedPropertiesDeep to fix changing tuple-type to array-type --- source/camel-cased-properties-deep.d.ts | 27 +++++++++++++++++++------ test-d/camel-cased-properties-deep.ts | 3 +++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/source/camel-cased-properties-deep.d.ts b/source/camel-cased-properties-deep.d.ts index b44482be6..fd8a81dcd 100644 --- a/source/camel-cased-properties-deep.d.ts +++ b/source/camel-cased-properties-deep.d.ts @@ -46,9 +46,24 @@ const result: CamelCasedPropertiesDeep = { */ export type CamelCasedPropertiesDeep = Value extends Function ? Value - : Value extends Array - ? Array> - : Value extends Set - ? Set> : { - [K in keyof Value as CamelCase]: CamelCasedPropertiesDeep; - }; + : Value extends [] + ? [] + // Tailing spread array + : Value extends [infer U, ...infer V] + ? [CamelCasedPropertiesDeep, ...CamelCasedPropertiesDeep] + : Value extends readonly [infer U, ...infer V] + ? readonly [CamelCasedPropertiesDeep, ...CamelCasedPropertiesDeep] + // Leading spread array + : Value extends readonly [...infer U, infer V] + ? [...CamelCasedPropertiesDeep, CamelCasedPropertiesDeep] + : Value extends readonly [...infer U, infer V] + ? readonly [...CamelCasedPropertiesDeep, CamelCasedPropertiesDeep] + // Array + : Value extends Array + ? Array> + : Value extends ReadonlyArray + ? ReadonlyArray> + : Value extends Set + ? Set> : { + [K in keyof Value as CamelCase]: CamelCasedPropertiesDeep; + }; diff --git a/test-d/camel-cased-properties-deep.ts b/test-d/camel-cased-properties-deep.ts index 5f79ebd2e..83c1a1d4d 100644 --- a/test-d/camel-cased-properties-deep.ts +++ b/test-d/camel-cased-properties-deep.ts @@ -19,6 +19,9 @@ expectType<{fooBAR: number; baz: {fooBAR: number; bARFoo: string}}>(baz); declare const biz: CamelCasedPropertiesDeep; expectType<{fooBar: number; baz: {fooBar: number; barFoo: string}}>(biz); +declare const tuple: CamelCasedPropertiesDeep<{tuple: [number, string, {D: string}]}>; +expectType<{tuple: [number, string, {d: string}]}>(tuple); + // Verify example type User = { UserId: number;