Skip to content

Commit

Permalink
Make types for capitalize infer format for constant strings
Browse files Browse the repository at this point in the history
This PR improves the types of `capitalize` on `string.ts`
  • Loading branch information
rafawendel authored Jun 21, 2024
1 parent 069b26c commit aa26620
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* capitalize('hello') -> 'Hello'
* capitalize('va va voom') -> 'Va va voom'
*/
export const capitalize = (str: string): string => {
export const capitalize = <const Str extends string>(str: Str): Capitalize<Str> => {

Check failure on line 7 in src/string.ts

View workflow job for this annotation

GitHub Actions / verify-cdn-build-matches-src

'>' expected.

Check failure on line 7 in src/string.ts

View workflow job for this annotation

GitHub Actions / verify-cdn-build-matches-src

',' expected.

Check failure on line 7 in src/string.ts

View workflow job for this annotation

GitHub Actions / verify-cdn-build-matches-src

',' expected.

Check failure on line 7 in src/string.ts

View workflow job for this annotation

GitHub Actions / verify-cdn-build-matches-src

')' expected.

Check failure on line 7 in src/string.ts

View workflow job for this annotation

GitHub Actions / verify-cdn-build-matches-src

Unexpected keyword or identifier.

Check failure on line 7 in src/string.ts

View workflow job for this annotation

GitHub Actions / verify-cdn-build-matches-src

Declaration or statement expected.

Check failure on line 7 in src/string.ts

View workflow job for this annotation

GitHub Actions / verify-cdn-build-matches-src

Declaration or statement expected.

Check failure on line 7 in src/string.ts

View workflow job for this annotation

GitHub Actions / verify-cdn-build-matches-src

';' expected.
if (!str || str.length === 0) return ''
const lower = str.toLowerCase()
return lower.substring(0, 1).toUpperCase() + lower.substring(1, lower.length)
Expand Down

0 comments on commit aa26620

Please sign in to comment.