Codegen refuses Record<string, T> in a TypeScript TurboModule spec: Unrecognized generic type 'Record'

Offen
#59,981 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 2 Tagen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
70/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
javascript, react-native, typescript
Bereich
build-system, mobile

Rechercherichtung

Start with packages/react-native-codegen/src/parsers/typescript/modules/index.js, especially translateTypeReferenceAnnotation and the existing emitDictionary path; then inspect the common type table in parsers-primitives.js. Compare the schemas for Record<string, T>, Readonly<Record<string, T>>, index signatures, and CodegenTypes.UnsafeObject; done means both Record spellings produce the index-signature schema while the existing forms keep theirs.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Needs: Triage :mag: Type: New Architecture
Description

@react-native/codegen's TypeScript parser refuses Record<string, T> in a NativeModule spec, and Readonly<Record<string, T>> the same way, with Unrecognized generic type 'Record' in NativeModule spec., while it reads {[key: string]: T}, the type Record<string, T> names, as a dictionary of T.

On main (de7e643aa3) the refusal is the default branch of translateTypeReferenceAnnotation, since emitCommonTypes' table has no Record; a type literal with an index signature goes to emitDictionary.

Expected: Record<string, T> and Readonly<Record<string, T>> parse as {[key: string]: T} does, to a GenericObjectTypeAnnotation whose dictionaryValueType is T, and {[key: string]: T} and CodegenTypes.UnsafeObject keep the schema they get today.

Steps to reproduce
  1. Clone the reproducer below. ReproducerApp/specs/NativeSample.ts is a TurboModule spec with one method, setOptions(options: Record<string, unknown>): void.
  2. Run its repro.sh in a node:24 container:
    docker run --rm -v "$PWD:/repro:ro" node:24 bash /repro/repro.sh
    
    It installs react-native@nightly and parses the spec with @react-native/codegen/lib/cli/combine/combine-js-to-schema-cli.js, the script Android's generateCodegenSchemaFromJavaScript task runs, beside copies of the spec whose parameter is Readonly<Record<string, unknown>>, {[key: string]: unknown} and CodegenTypes.UnsafeObject.
  3. Expected: both Record spellings parse to the schema {[key: string]: unknown} gets. Actual: codegen refuses both:
    Record<string, unknown> -> UnsupportedGenericParserError: Module NativeSample: Unrecognized generic type 'Record' in NativeModule spec.
    Readonly<Record<string, unknown>> -> UnsupportedGenericParserError: Module NativeSample: Unrecognized generic type 'Record' in NativeModule spec.
    
    bash /repro/repro.sh 0.88.1 shows the same on the latest stable.
React Native Version

0.88.1

Affected Platforms

Build - Linux

Areas

TurboModule - The New Native Module System, Codegen

Output of npx @react-native-community/cli info
System:
  OS: Linux 6.18 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
  CPU: (24) x64 AMD Ryzen 9 9950X3D 16-Core Processor
  Memory: 120.26 GB / 125.63 GB
  Shell:
    version: 5.2.15
    path: /bin/bash
Binaries:
  Node:
    version: 24.22.2
    path: /usr/local/bin/node
  Yarn:
    version: 1.22.22
    path: /usr/local/bin/yarn
  npm:
    version: 11.19.1
    path: /usr/local/bin/npm
  Watchman: Not Found
SDKs:
  Android SDK: Not Found
IDEs:
  Android Studio: Not Found
Languages:
  Java: Not Found
  Ruby: Not Found
npmPackages:
  "@react-native-community/cli": Not Found
  react: Not Found
  react-native:
    installed: 0.90.0-nightly-20261112-897cca827
    wanted: ^0.90.0-nightly-20261112-897cca827
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: Not found
  newArchEnabled: Not found
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found
Stacktrace or Logs
== install react-native@nightly
react-native 0.90.0-nightly-20261112-897cca827 with @react-native/codegen 0.90.0-nightly-20261112-897cca827
== parse each spelling of the parameter with node_modules/@react-native/codegen/lib/cli/combine/combine-js-to-schema-cli.js
Record<string, unknown> -> UnsupportedGenericParserError: Module NativeSample: Unrecognized generic type 'Record' in NativeModule spec.
Readonly<Record<string, unknown>> -> UnsupportedGenericParserError: Module NativeSample: Unrecognized generic type 'Record' in NativeModule spec.
{[key: string]: unknown} -> {"type":"GenericObjectTypeAnnotation","dictionaryValueType":{"type":"GenericObjectTypeAnnotation"}}
CodegenTypes.UnsafeObject -> {"type":"GenericObjectTypeAnnotation"}
SUMMARY: react-native 0.90.0-nightly-20261112-897cca827's codegen does not read Record<string, unknown> as it reads {[key: string]: unknown}
MANDATORY Reproducer

https://github.com/YevheniiKotyrlo/react-native-codegen-record-in-module-spec

Screenshots and Videos

No response

Vorherrschende Sprache
C++
Sterne
127k
Forks
25.5k
Ø Merge
3 T. 22 Std.
Gemergte PRs (30 T.)
235

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus react/react-native

Alle Issues in react/react-native

Ähnliche Issues

Weitere Issues zu C++

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.