react-native-tscodegen
TypeScript icon, indicating that this package has built-in type declarations

0.72.0 • Public • Published

Welcome to react-native-tscodegen (beta)!

This library enable people to write react-native Turbo Module in TypeScript, and generate native code in C++, Objective C++ and Java!

Target react-native version

0.70.1

Authoring a Turbo Module

At this moment, the new Turbo Module API is not published by Facebook, you need npm package react-native-tscodegen-types to access these new APIs. Here is an example of a very simple Turbo Module TypeScript file: ./src/turboModule.ts.

import { TurboModule, TurboModuleRegistry } from 'react-native-tscodegen-types';

export interface Spec extends TurboModule {
  getHello(name: string): string;
}

// tslint:disable-next-line
export default (TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule') as Spec);

Code generation

In order to do code generation, you need an extra JSON file for this TypeScript file. They are one-to-one mapping for now, if you have multiple TypeScript files, you need multiple JSON files This will be improved in the future.

Name the following file as react-native-tscodegen.json

{
    "libraryName": "PlaygroundModule",
    "outputDirectory": "./lib/cpp-generated",
    "moduleSpecName": "PlaygroundModuleSpec",
    "generators": [
        "descriptors",
        "events",
        "props",
        "tests",
        "shadow-nodes", 
        "modulesAndroid",
        "modulesCxx",
        "modulesIOS"
    ],
    "inputFile": "./src/turboModule.ts"
}

And add this script to your package.json

{
  "scripts": {
    "codegen": "react-native-tscodegen ./react-native-tscodegen.json"
  }
}

After running npm run codegen, you will see files get generated in ./lib/cpp-generated.

Building C++ files

You are expected to use react-native-windows for implementing turbo modules in C++.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.72.02latest

Version History

VersionDownloads (Last 7 Days)Published
0.72.02
0.71.10
0.71.00
0.68.5647
0.68.41
0.68.30
0.68.21
0.68.10
0.68.00
0.67.04,721
0.66.11
0.66.01
0.65.30
0.65.20
0.65.10
0.65.00
0.64.00
0.62.20
0.62.10
0.0.100
0.0.90
0.0.80
0.0.70
0.0.50
0.0.40
0.0.30
0.0.20
0.0.10

Package Sidebar

Install

npm i react-native-tscodegen

Weekly Downloads

5,374

Version

0.72.0

License

MIT

Unpacked Size

649 kB

Total Files

104

Last publish

Collaborators

  • acoates
  • rnbot
  • zihanc
  • microsoft1es