Skip to content

Commit

Permalink
Fix CamelCase behavior when value is in uppercase (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
My42 authored Jun 16, 2021
1 parent c95adc8 commit 10516fb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion test-d/camel-case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ expectType<'veryPrefixed'>(camelFromDoublePrefixedKebab);
const camelFromRepeatedSeparators: CamelCase<'foo____bar'> = 'fooBar';
expectType<'fooBar'>(camelFromRepeatedSeparators);

const camelFromUppercase: CamelCase<'FOO'> = 'foo';
expectType<'foo'>(camelFromUppercase);

const camelFromLowercase: CamelCase<'foo'> = 'foo';
expectType<'foo'>(camelFromLowercase);

// Verifying example
type CamelCasedProperties<T> = {
[K in keyof T as CamelCase<K>]: T[K]
Expand All @@ -46,10 +52,12 @@ interface RawOptions {
'dry-run': boolean;
'full_family_name': string;
foo: number;
BAR: string;
}

expectAssignable<CamelCasedProperties<RawOptions>>({
dryRun: true,
fullFamilyName: 'bar.js',
foo: 123
foo: 123,
bar: 'foo'
});
2 changes: 1 addition & 1 deletion ts41/camel-case.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ const dbResult: CamelCasedProperties<ModelProps> = {
@category Template Literals
*/
export type CamelCase<K> = K extends string ? CamelCaseStringArray<Split<K, WordSeparators>> : K;
export type CamelCase<K> = K extends string ? K extends Uppercase<K> ? Lowercase<K> : CamelCaseStringArray<Split<K, WordSeparators>> : K;

0 comments on commit 10516fb

Please sign in to comment.