]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor(types): improve capitalize types (#6212)
authorqiang <qw13131wang@gmail.com>
Sun, 9 Jul 2023 11:37:32 +0000 (19:37 +0800)
committerGitHub <noreply@github.com>
Sun, 9 Jul 2023 11:37:32 +0000 (19:37 +0800)
packages/shared/src/general.ts

index b36ec89c65f3fce0fef6a18f225d18977f0dcf45..4138b2730e6b235cf7ce26cf71aea342b5b42e51 100644 (file)
@@ -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 =>