Image.resolveAssetSource's TypeScript declaration drops the null it returns for an unknown asset
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- react-native, typescript
- Domain
- mobile
Research direction
Read types_generated/Libraries/Image/ImageTypes.flow.d.ts and compare its return type for Image.resolveAssetSource with the Flow declaration in Libraries/Image/ImageTypes.flow.js and implementation in Libraries/Image/resolveAssetSource.js. Update the TypeScript declaration to include the returned null, then check the generated declaration and its type behavior against the reproducer described in the issue.
Written by the indexing model from the issue text.
Description
Description
Image.resolveAssetSource returns null for an asset id the asset registry does not hold (resolveAssetSource.js L118-L121), and its Flow type says so: resolveAssetSource(source: ImageSource): ?ImageResolvedAssetSource (ImageTypes.flow.js L62). The generated TypeScript declaration, types_generated/Libraries/Image/ImageTypes.flow.d.ts, declares it as returning ImageResolvedAssetSource | undefined, without the null. TypeScript code that rules out undefined therefore type-checks and then throws on the null the function returns.
Steps to reproduce
- Clone https://github.com/YevheniiKotyrlo/react-native-typescript-declarations and run
yarn installinReproducerApp. It runs[email protected]with TypeScript 7.0.2. declarations/resolve-asset-source.tsreads theuriofImage.resolveAssetSource(assetId)once the result is notundefined. Runyarn check:resolve-asset-source, which type-checks it withstrict: true.- Run
yarn jest __tests__/resolveAssetSource-test.ts. Its first test checks thatImage.resolveAssetSource(123456)returnsnull; its second calls the function from step 2 with that id.
Expected: step 2 reports 'resolved' is possibly 'null', since the function can return null.
Seen: step 2 passes with no errors, the first test of step 3 passes, and the second throws TypeError: Cannot read properties of null (reading 'uri'). 0.88.1 declares the same ImageResolvedAssetSource | undefined.
React Native Version
0.88.1, and 0.89.0-nightly-20261029-25b05acd7
Affected Platforms
Other (please specify)
Output of npx @react-native-community/cli info
System:
OS: Windows 11 10.0.26300
Binaries:
Node:
version: 26.12.1
Yarn:
version: 1.22.22
npmPackages:
"@react-native-community/cli":
installed: 20.2.0
wanted: 20.2.0
react:
installed: 19.3.0
wanted: 19.3.0
react-native:
installed: 0.89.0-nightly-20261029-25b05acd7
wanted: 0.89.0-nightly-20261029-25b05acd7
The defect is in the published TypeScript declarations, so it shows on every platform; the reproducer runs tsc and Jest.
Stacktrace or Logs
$ yarn check:resolve-asset-source
(no output; tsc exits 0)
$ yarn jest __tests__/resolveAssetSource-test.ts
FAIL __tests__/resolveAssetSource-test.ts
√ resolveAssetSource returns null for an asset id the registry does not hold (104 ms)
× code the declaration accepts reads uri of that null (7 ms)
● code the declaration accepts reads uri of that null
expect(received).not.toThrow()
Error name: "TypeError"
Error message: "Cannot read properties of null (reading 'uri')"
5 | export function uriOf(assetId: number): string {
6 | const resolved = Image.resolveAssetSource(assetId);
> 7 | return resolved !== undefined ? resolved.uri : 'missing';
| ^
8 | }
9 |
MANDATORY Reproducer
https://github.com/YevheniiKotyrlo/react-native-typescript-declarations
Screenshots and Videos
None: the failure is the type checker's and Jest's output above.
- Dominant language
- C++
- Stars
- 127k
- Forks
- 25.4k
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 34
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from react/react-native
-
Linking.getInitialURL() returns the task's first link after a link relaunches a reclaimed Android appPossibly taken @YevheniiKotyrlo claimed this 15 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
react/react-native#59006 · 2 comments ·
Maintainers usually reply within 2 days
-
Fabric TextInput: prepareForRecycle leaves stale inputAccessoryViewButtonLabel (empty Done bar)Possibly taken @jkasprzyk17 claimed this 15 days ago. OpenNeeds: Author Feedback Needs: Repro
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
react/react-native#58952 · 1 comment ·
Maintainers usually reply within 2 days
-
[iOS][Fabric] TextInput drops a keystroke right after the first character typed into an empty field (_textOf:equals: compares attributes of a focused field)Possibly taken A pull request linked to this issue is open or already merged. OpenNeeds: Attention Needs: Repro
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
react/react-native#58904 · 3 comments ·
Maintainers usually reply within 2 days
-
Needs: Author Feedback Needs: Repro
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
react/react-native#58659 · 2 comments ·
Maintainers usually reply within 2 days
-
Add TypeScript declaration for the performance globalPossibly taken @Cedric921 claimed this 25 days ago. OpenNeeds: Attention Needs: Repro
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
react/react-native#58610 · 5 comments ·
Maintainers usually reply within 2 days
All issues in react/react-native
Similar issues
-
.NET ep:WebGPU platform:web
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
microsoft/onnxruntime#33755 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
grumpycoders/pcsx-redux#2530 ·
-
A-tools P-medium S-ready-to-start studio task
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
Status: Needs confirmation Status: Needs triage Type: Code Quality
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
platform: Linux
Difficulty 1/5 Under an hour Newbie friendliness 80/100
keepassxreboot/keepassxc#13947 ·
Maintainers usually reply within 1 day