Skip to content

Support importing types across Turbo Module specs#56045

Open
christophpurrer wants to merge 1 commit intofacebook:mainfrom
christophpurrer:export-D95646987
Open

Support importing types across Turbo Module specs#56045
christophpurrer wants to merge 1 commit intofacebook:mainfrom
christophpurrer:export-D95646987

Conversation

@christophpurrer
Copy link
Contributor

Summary:

Changelog:

[General] [Added] - Add cross-file type import support for React Native Turbo Module codegen

Turbo Module JavaScript specs previously required all types (enums, type aliases)
to be defined in the same file. This forced developers to duplicate type
definitions when sharing them across multiple modules.

This diff adds an optional importedTypes parameter to parseString() that
allows the parser to resolve types defined in external files. The approach:

  • parseString() accepts an optional TypeDeclarationMap of imported types,
    which are merged with local types (local definitions take precedence).
  • parseFile() automatically resolves relative import type declarations by
    parsing the source files and extracting their type AST nodes.
  • A shared resolveImportedTypes() utility handles filesystem resolution for
    both Flow and TypeScript parsers.
  • getImportsFromAST() extracts type-only import declarations from the AST,
    filtering out value imports to avoid unnecessary filesystem I/O.
  • The flow-schema OTA safety tool is updated to build imported types from its
    existing import map infrastructure and pass them to the codegen parser.

Code generators require zero changes since they consume the flat schema
(enumMap/aliasMap), and imported types produce identical schema entries to
file-local types.

Differential Revision: D95646987

Summary:
## Changelog:

[General] [Added] - Add cross-file type import support for React Native Turbo Module codegen


Turbo Module JavaScript specs previously required all types (enums, type aliases)
to be defined in the same file. This forced developers to duplicate type
definitions when sharing them across multiple modules.

This diff adds an optional `importedTypes` parameter to `parseString()` that
allows the parser to resolve types defined in external files. The approach:

- `parseString()` accepts an optional `TypeDeclarationMap` of imported types,
  which are merged with local types (local definitions take precedence).
- `parseFile()` automatically resolves relative `import type` declarations by
  parsing the source files and extracting their type AST nodes.
- A shared `resolveImportedTypes()` utility handles filesystem resolution for
  both Flow and TypeScript parsers.
- `getImportsFromAST()` extracts type-only import declarations from the AST,
  filtering out value imports to avoid unnecessary filesystem I/O.
- The flow-schema OTA safety tool is updated to build imported types from its
  existing import map infrastructure and pass them to the codegen parser.

Code generators require zero changes since they consume the flat schema
(enumMap/aliasMap), and imported types produce identical schema entries to
file-local types.

Differential Revision: D95646987
@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 10, 2026
@meta-codesync
Copy link

meta-codesync bot commented Mar 10, 2026

@christophpurrer has exported this pull request. If you are a Meta employee, you can view the originating Diff in D95646987.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants