From 476024da197ec8de273596cdf177ec4bcbbe2ef9 Mon Sep 17 00:00:00 2001 From: Dmitry Firsov Date: Wed, 26 Jun 2024 15:40:37 +0300 Subject: [PATCH] `CamelCasedPropertiesDeep`: Fix handling of non-recursive types inside target type (#890) --- source/camel-cased-properties-deep.d.ts | 3 ++- test-d/camel-cased-properties-deep.ts | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/source/camel-cased-properties-deep.d.ts b/source/camel-cased-properties-deep.d.ts index 8ba3491d7..d7756fd48 100644 --- a/source/camel-cased-properties-deep.d.ts +++ b/source/camel-cased-properties-deep.d.ts @@ -1,4 +1,5 @@ import type {CamelCase, CamelCaseOptions} from './camel-case'; +import type {NonRecursiveType} from './internal'; import type {UnknownArray} from './unknown-array'; /** @@ -48,7 +49,7 @@ const result: CamelCasedPropertiesDeep = { export type CamelCasedPropertiesDeep< Value, Options extends CamelCaseOptions = {preserveConsecutiveUppercase: true}, -> = Value extends Function +> = Value extends NonRecursiveType ? Value : Value extends UnknownArray ? CamelCasedPropertiesArrayDeep diff --git a/test-d/camel-cased-properties-deep.ts b/test-d/camel-cased-properties-deep.ts index 83c1a1d4d..c5054f1b5 100644 --- a/test-d/camel-cased-properties-deep.ts +++ b/test-d/camel-cased-properties-deep.ts @@ -1,5 +1,5 @@ import {expectType} from 'tsd'; -import type {CamelCasedPropertiesDeep} from '../index'; +import type {CamelCasedPropertiesDeep, Tagged} from '../index'; declare const foo: CamelCasedPropertiesDeep<{A: {B: number; C: Array<{D: string}>}}>; @@ -23,11 +23,14 @@ declare const tuple: CamelCasedPropertiesDeep<{tuple: [number, string, {D: strin expectType<{tuple: [number, string, {d: string}]}>(tuple); // Verify example +type UserRole = Tagged; + type User = { UserId: number; UserName: string; Date: Date; RegExp: RegExp; + Role: UserRole; }; type UserWithFriends = { @@ -35,12 +38,15 @@ type UserWithFriends = { UserFriends: User[]; }; +const role = 'someRole' as UserRole; + const result: CamelCasedPropertiesDeep = { userInfo: { userId: 1, userName: 'Tom', date: new Date(), regExp: /.*/, + role, }, userFriends: [ { @@ -48,12 +54,14 @@ const result: CamelCasedPropertiesDeep = { userName: 'Jerry', date: new Date(), regExp: /.*/, + role, }, { userId: 3, userName: 'Spike', date: new Date(), regExp: /.*/, + role, }, ], };