Skip to content

Commit 38f662c

Browse files
author
Filipe Miranda
committed
Fixes objectToCamel typing
1 parent 71a175e commit 38f662c

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/caseConvert.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export type ObjectToCamel<T extends object | undefined | null> =
110110
? null
111111
: T extends Array<infer ArrayType>
112112
? ArrayType extends object
113-
? Array<ObjectToPascal<ArrayType>>
113+
? Array<ObjectToCamel<ArrayType>>
114114
: Array<ArrayType>
115115
: {
116116
[K in keyof T as ToCamel<K>]: T[K] extends

test/caseConvert.bugs.test.ts

+16
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
ObjectToCamel,
33
ObjectToPascal,
44
ObjectToSnake,
5+
objectToCamel
56
} from '../src/caseConvert';
67

78
describe('bug fixes', () => {
@@ -73,6 +74,21 @@ describe('bug fixes', () => {
7374
expect(value.index).toEqual(0);
7475
});
7576
});
77+
78+
it('#52 - objectToCamel return type is a Pascal-cased array when the input is a snake-typed array', () => {
79+
type SnakeTyped = { key: string; another_key: string }
80+
type CamelType = { key: string; anotherKey: string }
81+
82+
const snakeObject: SnakeTyped[] = [
83+
{ key: 'a', another_key: 'b' },
84+
];
85+
86+
const camelObject: CamelType[] = objectToCamel(snakeObject);
87+
88+
expect(Object.keys(camelObject[0])).toEqual(['key', 'anotherKey']);
89+
expect(camelObject[0].key).toEqual('a');
90+
expect(camelObject[0].anotherKey).toEqual('b');
91+
});
7692
});
7793

7894
// Bug #50

0 commit comments

Comments
 (0)