FIX: React Native Crash on Start with theta-client 1.11

Thanks to @Phat_Ca for his work using theta-client-react-native with TypeScript.

While I was building this tutorial, I ran into a linter error that showed the modules for initialize and getThetaInfo could not be found.

Phat solved the problem by creating a file to export the modules. In src/types/theta-client-react-native.d.ts, he added this:

declare module 'theta-client-react-native' {
  export function initialize(url: string, config?: any): Promise<void>;
  export function getThetaInfo(): Promise<any>;
  // Add other functions you use from the module
}

To make sure TypeScript can find the declaration, he modified tsconfig.json as follows:

{
  "extends": "@react-native/typescript-config/tsconfig.json",
  "compilerOptions": {
    "typeRoots": [
      "./node_modules/@types",
      "./src/types"
    ],
    "paths": {
      "theta-client-react-native": ["./src/types/theta-client-react-native.d.ts"]
    }
  },
  "include": ["src/**/*"]
}

As this can be daunting to export every functioned used, he opened an issue on the RICOH GitHub repo for theta-client to see if the TypeScript declarations already exist or if we need to export every module ourselves.


Phat’s configuration for React Native 0.77 with TypeScript module exports in shown in his GitHub repo.

There may be usable information in this article

Create React App + TypeScript Linting with TSLint and Prettier setup on VSCode · GitHub

1 Like