Skip to content

Commit

Permalink
refactor(types): improve capitalize types (#6212)
Browse files Browse the repository at this point in the history
  • Loading branch information
tolking authored Jul 9, 2023
1 parent 7121c92 commit eee7090
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/shared/src/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,17 @@ export const hyphenate = cacheStringFunction((str: string) =>
/**
* @private
*/
export const capitalize = cacheStringFunction(
(str: string) => str.charAt(0).toUpperCase() + str.slice(1)
)
export const capitalize = cacheStringFunction(<T extends string>(str: T) => {
return (str.charAt(0).toUpperCase() + str.slice(1)) as Capitalize<T>
})

/**
* @private
*/
export const toHandlerKey = cacheStringFunction((str: string) =>
str ? `on${capitalize(str)}` : ``
)
export const toHandlerKey = cacheStringFunction(<T extends string>(str: T) => {
const s = str ? `on${capitalize(str)}` : ``
return s as T extends '' ? '' : `on${Capitalize<T>}`
})

// compare whether a value has changed, accounting for NaN.
export const hasChanged = (value: any, oldValue: any): boolean =>
Expand Down

0 comments on commit eee7090

Please sign in to comment.