Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

Image.resolveAssetSource's TypeScript declaration drops the null it returns for an unknown asset

Aberta Para iniciantes
#59,648 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 2 dias

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
78/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
react-native, typescript
Domínio
mobile

Direção de pesquisa

Leia types_generated/Libraries/Image/ImageTypes.flow.d.ts e compare o tipo de retorno de Image.resolveAssetSource com a declaração Flow em Libraries/Image/ImageTypes.flow.js e a implementação em Libraries/Image/resolveAssetSource.js. Atualize a declaração TypeScript para incluir o null retornado e, em seguida, confira a declaração gerada e seu comportamento de tipos usando o reproducer descrito na issue.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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
  1. Clone https://github.com/YevheniiKotyrlo/react-native-typescript-declarations and run yarn install in ReproducerApp. It runs [email protected] with TypeScript 7.0.2.
  2. declarations/resolve-asset-source.ts reads the uri of Image.resolveAssetSource(assetId) once the result is not undefined. Run yarn check:resolve-asset-source, which type-checks it with strict: true.
  3. Run yarn jest __tests__/resolveAssetSource-test.ts. Its first test checks that Image.resolveAssetSource(123456) returns null; 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.

Linguagem predominante
C++
Estrelas
127k
Forks
25.4k
Merge médio
1d 17h
PRs com merge (30d)
34

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de react/react-native

Todas as issues de react/react-native

Issues semelhantes

Mais issues de C++

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.