react / react/react-native

Codegen chokes on imported types

未关闭
#38,769 7 条评论 2 个 reaction 已指派 1 人 在 GitHub 查看

@dmytrorykun 已经在做这个了。

开始于 2023年10月30日。

Needs: React Native Team Attention Never gets stale Tech: Codegen Type: New Architecture
主要语言
C++
星标
127k
派生
25.3k
平均合并
1 天 23 小时
30 天内合并 PR
4

描述

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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。