diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts index f3fee4c45e7..a64b53da6e2 100644 --- a/packages/shared/src/index.ts +++ b/packages/shared/src/index.ts @@ -52,7 +52,8 @@ export const isMap = (val: unknown): val is Map => export const isSet = (val: unknown): val is Set => toTypeString(val) === '[object Set]' -export const isDate = (val: unknown): val is Date => toTypeString(val) === '[object Date]' +export const isDate = (val: unknown): val is Date => + toTypeString(val) === '[object Date]' export const isFunction = (val: unknown): val is Function => typeof val === 'function' export const isString = (val: unknown): val is string => typeof val === 'string' @@ -99,7 +100,7 @@ const cacheStringFunction = string>(fn: T): T => { return ((str: string) => { const hit = cache[str] return hit || (cache[str] = fn(str)) - }) as any + }) as T } const camelizeRE = /-(\w)/g @@ -121,16 +122,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((str: T) => { + return (str.charAt(0).toUpperCase() + str.slice(1)) as Capitalize +}) /** * @private */ -export const toHandlerKey = cacheStringFunction((str: string) => - str ? `on${capitalize(str)}` : `` -) +export const toHandlerKey = cacheStringFunction((str: T) => { + const s = str ? `on${capitalize(str)}` : `` + return s as T extends '' ? '' : `on${Capitalize}` +}) // compare whether a value has changed, accounting for NaN. export const hasChanged = (value: any, oldValue: any): boolean =>