Files
react-native/packages/react-native-codegen
Vojtech Novak 90871861ce fix: codegen crash when parsing TS interfaces (#35492)
Summary:
when I'm defining a turbomodule spec, I tried to extract a common parameter into an interface.

The error I get is this:

```
[Codegen] >>>>> Processing RNSimpleToastSpec

[Codegen] Done.
/Users/vojta/_dev/_own/simple-toast/example/node_modules/react-native-codegen/lib/parsers/typescript/utils.js:111
        throw error;
        ^

TypeError: Cannot read properties of undefined (reading 'length')
    at isModuleInterface (/Users/vojta/_dev/_own/simple-toast/example/node_modules/react-native-codegen/lib/parsers/typescript/modules/index.js:695:18)
    at Array.filter (<anonymous>)
    at buildModuleSchema (/Users/vojta/_dev/_own/simple-toast/example/node_modules/react-native-codegen/lib/parsers/typescript/modules/index.js:709:44)
    at /Users/vojta/_dev/_own/simple-toast/example/node_modules/react-native-codegen/lib/parsers/typescript/index.js:158:9
    at guard (/Users/vojta/_dev/_own/simple-toast/example/node_modules/react-native-codegen/lib/parsers/typescript/utils.js:108:14)
    at buildSchema (/Users/vojta/_dev/_own/simple-toast/example/node_modules/react-native-codegen/lib/parsers/typescript/index.js:157:22)
    at Object.parseFile (/Users/vojta/_dev/_own/simple-toast/example/node_modules/react-native-codegen/lib/parsers/typescript/index.js:185:10)
```

After the fix I get this:

```
[Codegen] >>>>> Processing RNSimpleToastSpec

[Codegen] Done.
/Users/vojta/_dev/_own/simple-toast/example/node_modules/react-native-codegen/lib/parsers/typescript/utils.js:111
        throw error;
        ^

Invariant Violation: GenericTypeAnnotation 'Styles' must resolve to a TSTypeAliasDeclaration. Instead, it resolved to a 'TSInterfaceDeclaration'
```

Then I know that I should not be using an `interface` but a `type`

## Changelog

[Internal] [Fixed] - TS codegen crash when parsing interfaces

Pull Request resolved: https://github.com/facebook/react-native/pull/35492

Test Plan:
tested locally

let me know if you want an automated test

Reviewed By: cortinico

Differential Revision: D41548015

Pulled By: cipolleschi

fbshipit-source-id: 9acf02dffbb084831690f665357fb80225cbce0d
2022-11-28 04:19:47 -08:00
..
2022-11-23 01:41:23 -08:00
2022-02-22 02:23:02 -08:00
2020-09-29 14:39:40 -07:00
2022-11-17 08:04:00 -08:00

react-native-codegen

Version

Installation

yarn add --dev react-native-codegen

Note: We're using yarn to install deps. Feel free to change commands to use npm 3+ and npx if you like

Testing

To run the tests in this package, run the following commands from the react Native root folder:

  1. yarn to install the dependencies. You just need to run this once
  2. yarn jest react-native-codegen.