fix(shared): toNumber should only coerce strings

This commit is contained in:
Evan You 2022-11-14 17:50:56 +08:00
parent eb2a83283c
commit b55846f05c
2 changed files with 3 additions and 2 deletions

View File

@ -423,7 +423,7 @@ function createSuspenseBoundary(
o: { parentNode, remove }
} = rendererInternals
const timeout = toNumber(vnode.props && vnode.props.timeout)
const timeout = vnode.props ? toNumber(vnode.props.timeout) : undefined
if (__DEV__) {
assertNumber(timeout, `Suspense timeout`)
}

View File

@ -163,10 +163,11 @@ export const looseToNumber = (val: any): any => {
}
/**
* Only conerces number-like strings
* "123-foo" will be returned as-is
*/
export const toNumber = (val: any): any => {
const n = Number(val)
const n = isString(val) ? Number(val) : NaN
return isNaN(n) ? val : n
}