Image.resolveAssetSource's TypeScript declaration drops the null it returns for an unknown asset
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 78/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- react-native, typescript
- 領域
- mobile
調査の方向性
types_generated/Libraries/Image/ImageTypes.flow.d.tsを読み、Image.resolveAssetSourceの戻り値の型を、Libraries/Image/ImageTypes.flow.jsのFlow宣言およびLibraries/Image/resolveAssetSource.jsの実装と比較してください。返されるnullを含めるようTypeScript宣言を更新し、その後、issueに記載された再現例を使って生成された宣言とその型の動作を確認してください。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- C++
- スター
- 127k
- フォーク
- 25.4k
- 平均マージ
- 2日 1時間
- マージ済み PR(30日)
- 67
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
react/react-native のほかの issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
react/react-native#59699 ·
メンテナーはふだん 2 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
react/react-native#59694 ·
メンテナーはふだん 2 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
react/react-native#59693 ·
メンテナーはふだん 2 日以内に返信
-
Linking.getInitialURL() returns the task's first link after a link relaunches a reclaimed Android app対応中かも @YevheniiKotyrlo が 16 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
react/react-native#59006 · コメント 2 件 ·
メンテナーはふだん 2 日以内に返信
-
Fabric TextInput: prepareForRecycle leaves stale inputAccessoryViewButtonLabel (empty Done bar)対応中かも @jkasprzyk17 が 16 日前に担当しました。 オープンNeeds: Author Feedback Needs: Repro
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
react/react-native#58952 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
react/react-native の issue をすべて見る
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
ROCm/FastFlowLM#887 ·
メンテナーはふだん 1 日以内に返信
-
paraview 6.2.0 uses Abseil 20260526 symbols but does not pin libabseil (undefined symbol with libabseil 20260817)対応中かも @jschueller が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
-
bug medium priority openmp tokenizer wrong result
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 92/100
apache/casbin-cpp#277 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
iamaisim/ProjectAirSim#241 ·
メンテナーはふだん 1 日以内に返信