Skip to content

Commit

Permalink
CamelCase: Fix handling of non-literal strings (#531)
Browse files Browse the repository at this point in the history
  • Loading branch information
rayrw committed Dec 25, 2022
1 parent 9f04028 commit 00b13f8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion source/camel-case.d.ts
Expand Up @@ -74,5 +74,7 @@ const dbResult: CamelCasedProperties<RawOptions> = {
@category Template literal
*/
export type CamelCase<Type, Options extends CamelCaseOptions = {preserveConsecutiveUppercase: true}> = Type extends string
? Uncapitalize<CamelCaseFromArray<SplitWords<Type extends Uppercase<Type> ? Lowercase<Type> : Type>, Options>>
? string extends Type
? Type
: Uncapitalize<CamelCaseFromArray<SplitWords<Type extends Uppercase<Type> ? Lowercase<Type> : Type>, Options>>
: Type;
3 changes: 3 additions & 0 deletions test-d/camel-case.ts
Expand Up @@ -75,3 +75,6 @@ expectType<CamelCase<'fooBARBiz', {preserveConsecutiveUppercase: false}>>('fooBa

expectType<CamelCase<'foo BAR-Biz_BUZZ'>>('fooBARBizBUZZ');
expectType<CamelCase<'foo BAR-Biz_BUZZ', {preserveConsecutiveUppercase: false}>>('fooBarBizBuzz');

expectType<CamelCase<string>>('string' as string);
expectType<CamelCase<string, {preserveConsecutiveUppercase: false}>>('string' as string);

0 comments on commit 00b13f8

Please sign in to comment.