react-native icon indicating copy to clipboard operation
react-native copied to clipboard

Add support to turbo module codegen for WritableMap type.

Open lucaswitch opened this issue 1 year ago • 5 comments

Description

Currently there is no support to codegen return a specific data structure as WritableMap.

This is currently supported

For example on a Turbo Module with name "example".


type SomeType: {
  id: string 
}

export interface Spec extends TurboModule{
  someMethod(): SomeType[]; 
}

That should generate a should generate a turbo module method called "public WritableArray someMethod(){}" definition on Java Turbo Module.

This is not currently supported


type SomeType: {
  id: string 
}

export interface Spec extends TurboModule{
  someMethod(): SomeType 
}

That should generate a should generate a turbo module method called "public WritableMap someMethod(){}" definition on Java Turbo Module. But actually gives the following error building on js codegen task:

 nodes: [
    Node {
      type: 'TSTypeReference',
      start: 3645,
      end: 3667,
      loc: SourceLocation {
        start: Position { line: 117, column: 49, index: 3645 },
        end: Position { line: 117, column: 71, index: 3667 },
        filename: undefined,
        identifierName: undefined
      },
      typeName: Node {
        type: 'Identifier',
        start: 3645,
        end: 3667,
        loc: SourceLocation {
          start: Position { line: 117, column: 49, index: 3645 },
          end: Position { line: 117, column: 71, index: 3667 },
          filename: undefined,
          identifierName: 'SomeType'
        },
        name: 'SomeType'
      }
    }
  ]

I think maybe the Turbo Module codegen does not have support to non primitive types only supporting: number, fuction, strings, arrays and objects. But the codegen could generate a Java structure that could have type safety for named properties javascript objects, or just accept a WritableMap as return type.

React Native Version

0.74.4

Output of npx react-native info

System: OS: Linux 5.19 Ubuntu 22.04.2 LTS 22.04.2 LTS (Jammy Jellyfish) CPU: (16) x64 AMD Ryzen 7 5700X 8-Core Processor Memory: 4.48 GB / 15.52 GB Shell: 5.1.16 - /bin/bash Binaries: Node: 19.9.0 - /usr/local/bin/node Yarn: 1.22.19 - /usr/local/bin/yarn npm: 9.6.3 - /usr/local/bin/npm Watchman: Not Found SDKs: Android SDK: API Levels: 28, 30, 33, 33 Build Tools: 30.0.3, 33.0.0, 33.0.2 System Images: android-30 | Google APIs Intel x86 Atom, android-33 | Google APIs Intel x86_64 Atom Android NDK: Not Found IDEs: Android Studio: Not Found Languages: Java: 11.0.19 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 18.2.0 => 18.2.0 react-native: 0.71.4 => 0.71.4 npmGlobalPackages: react-native: Not Found

Steps to reproduce

Declare a turbo module that implement this simple feature. Should crash on build time.

type SomeType: { id: string }

export interface Spec extends TurboModule{ someMethod(): SomeType }



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

![Screenshot from 2023-06-09 19-34-28](https://github.com/facebook/react-native/assets/29023475/655ee758-eb41-487a-988b-2d9afab6322a)
![Screenshot from 2023-06-09 19-34-42](https://github.com/facebook/react-native/assets/29023475/40a6c1ee-d951-4436-b89e-6836d1a7d332)
![Screenshot from 2023-06-09 19-34-54](https://github.com/facebook/react-native/assets/29023475/68724dbb-f138-4e45-b73c-8a3dbddd2a32)

lucaswitch avatar Jun 09 '23 22:06 lucaswitch

:warning: Add or Reformat Version Info
:information_source: We could not find or parse the version number of React Native in your issue report. Please use the template, and report your version including major, minor, and patch numbers - e.g. 0.70.2

github-actions[bot] avatar Jun 09 '23 22:06 github-actions[bot]

Cc: @cipolleschi

Pranav-yadav avatar Jun 10 '23 03:06 Pranav-yadav

Hi @lucaswitch, thank you for this issue. As far as I know, Codegen do support object types in TS and for Android.

Note that writeable map is not type safe as well, given that you still have to check the types in native code.

cipolleschi avatar Jun 12 '23 16:06 cipolleschi

Not sure if was a problem on my development environment, gonna test it again soon. Have a nice week.

lucaswitch avatar Jun 14 '23 01:06 lucaswitch

This issue is waiting for author's feedback since 24 days. Please provide the requested feedback or this will be closed in 7 days.

github-actions[bot] avatar Jul 09 '23 05:07 github-actions[bot]

This issue was closed because the author hasn't provided the requested feedback after 7 days.

github-actions[bot] avatar Jul 16 '23 05:07 github-actions[bot]

This issue was closed because it has been stalled for 7 days with no activity.

github-actions[bot] avatar Jul 16 '23 05:07 github-actions[bot]