@@ -52,7 +52,8 @@ export const isMap = (val: unknown): val is Map<any, any> =>
52
52
export const isSet = ( val : unknown ) : val is Set < any > =>
53
53
toTypeString ( val ) === '[object Set]'
54
54
55
- export const isDate = ( val : unknown ) : val is Date => toTypeString ( val ) === '[object Date]'
55
+ export const isDate = ( val : unknown ) : val is Date =>
56
+ toTypeString ( val ) === '[object Date]'
56
57
export const isFunction = ( val : unknown ) : val is Function =>
57
58
typeof val === 'function'
58
59
export const isString = ( val : unknown ) : val is string => typeof val === 'string'
@@ -99,7 +100,7 @@ const cacheStringFunction = <T extends (str: string) => string>(fn: T): T => {
99
100
return ( ( str : string ) => {
100
101
const hit = cache [ str ]
101
102
return hit || ( cache [ str ] = fn ( str ) )
102
- } ) as any
103
+ } ) as T
103
104
}
104
105
105
106
const camelizeRE = / - ( \w ) / g
@@ -121,16 +122,17 @@ export const hyphenate = cacheStringFunction((str: string) =>
121
122
/**
122
123
* @private
123
124
*/
124
- export const capitalize = cacheStringFunction (
125
- ( str : string ) => str . charAt ( 0 ) . toUpperCase ( ) + str . slice ( 1 )
126
- )
125
+ export const capitalize = cacheStringFunction ( < T extends string > ( str : T ) => {
126
+ return ( str . charAt ( 0 ) . toUpperCase ( ) + str . slice ( 1 ) ) as Capitalize < T >
127
+ } )
127
128
128
129
/**
129
130
* @private
130
131
*/
131
- export const toHandlerKey = cacheStringFunction ( ( str : string ) =>
132
- str ? `on${ capitalize ( str ) } ` : ``
133
- )
132
+ export const toHandlerKey = cacheStringFunction ( < T extends string > ( str : T ) => {
133
+ const s = str ? `on${ capitalize ( str ) } ` : ``
134
+ return s as T extends '' ? '' : `on${Capitalize < T > } `
135
+ } )
134
136
135
137
// compare whether a value has changed, accounting for NaN.
136
138
export const hasChanged = ( value : any , oldValue : any ) : boolean =>
0 commit comments