Make the conversions of parseInt and isNaN explicit

Summary:
TypeScript declares `parseInt(string: string, radix?: number)` and `isNaN(number: number)`, and Flow is adopting the same signatures. Calls that pass another type rely on the function's implicit conversion and start to error.

Wrap each such argument in `String(...)` (`parseInt`) or `Number(...)` (`isNaN`), the conversion the function already applies, so behavior doesn't change. The calls were found from Flow's errors and rewritten by a codemod. 8 arguments in 6 files in React Native and Metro.

Changelog: [Internal]

Differential Revision: D129644365

Pull Request resolved: https://github.com/react/react-native/pull/59799
This commit is contained in:
Sam Zhou authored and GitHub committed 2026-11-04 23:43:39 +00:00
1 parent ca4afe5d30
commit 25d63d471a
5 files changed
+6 -6

No files matched your search

@@ -215,7 +215,7 @@ function convertDefaultTypeToString(
return String(typeAnnotation.default);
case 'DoubleTypeAnnotation':
const defaultDoubleVal = typeAnnotation.default;
return parseInt(defaultDoubleVal, 10) === defaultDoubleVal
return parseInt(String(defaultDoubleVal), 10) === defaultDoubleVal
? typeAnnotation.default.toFixed(1)
: String(typeAnnotation.default);
case 'FloatTypeAnnotation':
@@ -223,7 +223,7 @@ function convertDefaultTypeToString(
if (defaultFloatVal == null) {
return '';
}
return parseInt(defaultFloatVal, 10) === defaultFloatVal
return parseInt(String(defaultFloatVal), 10) === defaultFloatVal
? defaultFloatVal.toFixed(1)
: String(typeAnnotation.default);
case 'ReservedPropTypeAnnotation':
@@ -25,7 +25,7 @@ component LogBoxInspectorStackFrame(
frame: StackFrame,
onPress?: ?(event: GestureResponderEvent) => void,
) {
const column = frame.column != null && parseInt(frame.column, 10);
const column = frame.column != null && parseInt(String(frame.column), 10);
const location =
getFileName(frame.file) +
(frame.lineNumber != null
@@ -152,7 +152,7 @@ const _getKeyAndValueFromCSSTransform: (
};
default:
return {key, value: !isNaN(args) ? Number(args) : args};
return {key, value: !isNaN(Number(args)) ? Number(args) : args};
}
};
@@ -205,7 +205,7 @@ export component SectionList_scrollable() {
}
const setItemPress = (item: Item) => {
if (isNaN(item.key)) {
if (isNaN(Number(item.key))) {
return;
}
const index = Number(item.key);
@@ -60,7 +60,7 @@ class XHRExampleDownload extends React.Component<{...}, any> {
const onreadystatechange = () => {
if (xhr.readyState === xhr.HEADERS_RECEIVED) {
const contentLength = parseInt(
xhr.getResponseHeader('Content-Length'),
String(xhr.getResponseHeader('Content-Length')),
10,
);
this.setState({