Open trivikr opened 2 months ago
:warning: | Add or Reformat Version Info |
---|---|
:information_source: | We could not find or parse the version number of React Native in your issue report. Please use the template, and report your version including major, minor, and patch numbers - e.g. 0.70.2 |
:warning: | Add or Reformat Version Info |
---|---|
:information_source: | We could not find or parse the version number of React Native in your issue report. Please use the template, and report your version including major, minor, and patch numbers - e.g. 0.70.2 |
The issue is reproducible in all supported React Native versions.
I updated the version in issue description to 0.74.3
which was used in reproducer.
The TypeScript types allow null and undefined in finally block https://github.com/microsoft/TypeScript/blob/12ae799eda74aca6a4051f1ebee4d2d0c8d817a2/src/lib/es2018.promise.d.ts#L11
However, the MDN for Promise.prototoype.finally() mentions onFinally
to be a function.
The MDN for Promise.prototype.then() states
If it is not a function, it is internally replaced with an identity function ((x) => x) which simply passes the fulfillment value forward.
We suspect that Node.js and browser replicate then()
behavior for finally()
when null or undefined is passed, so that application does not throw error.
In TC39 specification, there is a workaround if onFinally
is not callable in point 5.
Description
If the user code incorrectly passes
null
to finally block, react-native throwsTypeError: null is not a function
error.Neither Node.js or Browser calls a variable in finally if it's incorrectly set to null.
Node.js
Browser
Verified in Browser Console of
Google Chrome Version 127.0.6533.73 (Official Build) (arm64)
Steps to reproduce
Check the README of reproducer
React Native Version
0.74.3
Affected Platforms
Runtime - iOS
Output of
npx react-native info
Stacktrace or Logs
Reproducer
https://github.com/trivikr/react-native-type-error-null-is-not-a-function to reproduce
Screenshots and Videos
The bug was originally seen in AWS SDK for JavaScript v3 in https://github.com/aws/aws-sdk-js-v3/issues/6269#issuecomment-2252850763, where the error was thrown
In the reproducer app, the error is thrown, but it's shown as a warning in the React Native interface. Screenshots are provided in the README of reproducer