Skip to content

Commit

Permalink
CamelCasedPropertiesDeep: Fix handling of non-recursive types insid…
Browse files Browse the repository at this point in the history
…e target type (#890)
  • Loading branch information
Ghost-str authored Jun 26, 2024
1 parent 737550b commit 476024d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion source/camel-cased-properties-deep.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {CamelCase, CamelCaseOptions} from './camel-case';
import type {NonRecursiveType} from './internal';
import type {UnknownArray} from './unknown-array';

/**
Expand Down Expand Up @@ -48,7 +49,7 @@ const result: CamelCasedPropertiesDeep<UserWithFriends> = {
export type CamelCasedPropertiesDeep<
Value,
Options extends CamelCaseOptions = {preserveConsecutiveUppercase: true},
> = Value extends Function
> = Value extends NonRecursiveType
? Value
: Value extends UnknownArray
? CamelCasedPropertiesArrayDeep<Value>
Expand Down
10 changes: 9 additions & 1 deletion test-d/camel-cased-properties-deep.ts
Original file line number Diff line number Diff line change
@@ -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}>}}>;

Expand All @@ -23,37 +23,45 @@ declare const tuple: CamelCasedPropertiesDeep<{tuple: [number, string, {D: strin
expectType<{tuple: [number, string, {d: string}]}>(tuple);

// Verify example
type UserRole = Tagged<string, 'Role'>;

type User = {
UserId: number;
UserName: string;
Date: Date;
RegExp: RegExp;
Role: UserRole;
};

type UserWithFriends = {
UserInfo: User;
UserFriends: User[];
};

const role = 'someRole' as UserRole;

const result: CamelCasedPropertiesDeep<UserWithFriends> = {
userInfo: {
userId: 1,
userName: 'Tom',
date: new Date(),
regExp: /.*/,
role,
},
userFriends: [
{
userId: 2,
userName: 'Jerry',
date: new Date(),
regExp: /.*/,
role,
},
{
userId: 3,
userName: 'Spike',
date: new Date(),
regExp: /.*/,
role,
},
],
};
Expand Down

0 comments on commit 476024d

Please sign in to comment.