facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
118.96k stars 24.31k forks source link

Codegen chokes on imported types #38769

Open birdofpreyru opened 1 year ago

birdofpreyru commented 1 year ago

Description

It seems codegen currently chokes on types imported from a different module, i.e. consider this example:

// types.ts
export type MyType = {
  field: string;
};

// NativeReactNativeMyModule.ts
import type { TurboModule } from 'react-native';
import { TurboModuleRegistry } from 'react-native';

import { type MyType } from './types';

export interface Spec extends TurboModule {
  myMethod(arg: MyType): void;
}

export default TurboModuleRegistry.getEnforcing<Spec>('ReactNativeMyModule');

When running the build (for Android on Ubuntu system) the codegen chokes on the method definition saying UnsupportedGenericParserError: Module NativeReactNativeMyModule: Unrecognized generic type 'MyType' in NativeModule spec.

This equivalent code works fine though:

import type { TurboModule } from 'react-native';
import { TurboModuleRegistry } from 'react-native';

export type MyType = {
  field: string;
};

export interface Spec extends TurboModule {
  myMethod(arg: MyType): void;
}

export default TurboModuleRegistry.getEnforcing<Spec>('ReactNativeMyModule');

React Native Version

v0.72.3

Output of npx react-native info

N/A

Steps to reproduce

N/A

Snack, code example, screenshot, or link to a repository

N/A

github-actions[bot] commented 1 year ago
:warning: Missing Reproducible Example
:information_source: We could not detect a reproducible example in your issue report. Please provide either:
  • If your bug is UI related: a Snack
  • If your bug is build/update related: use our Reproducer Template. A reproducer needs to be in a GitHub repository under your username.
cipolleschi commented 1 year ago

Yes, that is a currently known limitation of codegen. The (very ugly) workaround is to copy-and-paste the types you need in the module definition.

We are currently working on solving this, so it will be hopefully available soon.

cc. @dmytrorykun

github-actions[bot] commented 6 months ago

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.