Image.resolveAssetSource's TypeScript declaration drops the null it returns for an unknown asset
Maintainer thường phản hồi trong vòng 2 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 78/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- react-native, typescript
- Lĩnh vực
- mobile
Hướng nghiên cứu
Đọc types_generated/Libraries/Image/ImageTypes.flow.d.ts và so sánh kiểu trả về của Image.resolveAssetSource với khai báo Flow trong Libraries/Image/ImageTypes.flow.js và phần triển khai trong Libraries/Image/resolveAssetSource.js. Cập nhật khai báo TypeScript để bao gồm null được trả về, sau đó kiểm tra khai báo đã tạo và hành vi kiểu của nó theo reproducer được mô tả trong issue.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- C++
- Star
- 127k
- Fork
- 25.4k
- Merge trung bình
- 1 ngày 17 giờ
- Pull request đã merge (30 ngày)
- 34
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của react/react-native
-
Linking.getInitialURL() returns the task's first link after a link relaunches a reclaimed Android appCó thể đã có người làm @YevheniiKotyrlo đã nhận 16 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
react/react-native#59006 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Fabric TextInput: prepareForRecycle leaves stale inputAccessoryViewButtonLabel (empty Done bar)Có thể đã có người làm @jkasprzyk17 đã nhận 15 ngày trước. Đang mởNeeds: Author Feedback Needs: Repro
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
react/react-native#58952 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[iOS][Fabric] TextInput drops a keystroke right after the first character typed into an empty field (_textOf:equals: compares attributes of a focused field)Có thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởNeeds: Attention Needs: Repro
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
react/react-native#58904 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Needs: Author Feedback Needs: Repro
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
react/react-native#58659 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Add TypeScript declaration for the performance globalCó thể đã có người làm @Cedric921 đã nhận 25 ngày trước. Đang mởNeeds: Attention Needs: Repro
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
react/react-native#58610 · 5 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của react/react-native
Issue tương tự
-
launch-client --save-creds creates creds/<account>/ with mode 755, not 700Có thể đã có người làm @metis-sprock đã nhận hôm nay. Đang mởbacklog bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
EchoTools/nevr-runtime#1471 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
.NET ep:WebGPU platform:web
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
microsoft/onnxruntime#33755 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
grumpycoders/pcsx-redux#2530 ·
-
A-tools P-medium S-ready-to-start studio task
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Status: Needs confirmation Status: Needs triage Type: Code Quality
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày