3

I have created an empty react-native project but using type-script (like react-native init MyApp --template typescript), then installed on that react-navigation-tabs package, and the problem which I am facing is:

TS7016: Could not find a declaration file for module 'react-navigation-tabs'.
'.../node_modules/react-navigation-tabs/src/index.js' implicitly has an 'any' type.
Try `npm install @types/react-navigation-tabs` if it exists
or add a new declaration (.d.ts) file containing `declare module 'react-navigation-tabs';`

I did also try npm install --save-dev @types/react-navigation-tabs, and since no such package did exist, for now I did workaround it like suggested in another post.

But coming back to the question in the title, it is really painful, I mean the information that the IDE needs to provide auto-completion are there, in the node_modules/react-navigation-tabs/src/index.js file, like:

/* @flow */
/* eslint-disable import/no-commonjs */

module.exports = {
  /**
   * Navigators
   */
  get createBottomTabNavigator() {
    return require('./navigators/createBottomTabNavigator').default;
  },
  get createMaterialTopTabNavigator() {
    return require('./navigators/createMaterialTopTabNavigator').default;
  },

  /**
   * Views
   */
  get BottomTabBar() {
    return require('./views/BottomTabBar').default;
  },
  get MaterialTopTabBar() {
    return require('./views/MaterialTopTabBar').default;
  },

  /**
   * Utils
   */
  get createTabNavigator() {
    return require('./utils/createTabNavigator').default;
  },
};

How can we make the IDE (e.g. VS Code) show auto-completion using the data it can find in the existing node_modules/react-navigation-tabs/src/index.js file ?

Edit: Also, created a request/question on github.

Top-Master
  • 7,611
  • 5
  • 39
  • 71
  • Those aren't types, where do you see types? – Patrick Roberts Apr 18 '19 at 12:05
  • sorry @PatrickRoberts, I do not know how to call them, but still, there are obviously usable information `exported` for the module, lets say, I want the IDE to recognize them. – Top-Master Apr 18 '19 at 12:07
  • 1
    TypeScript can only infer types from `.ts` files or `.d.ts` files, the `@flow` directive means nothing to it. – Patrick Roberts Apr 18 '19 at 12:11
  • Is there any `node-module` that can create such files for us? (although, the `package.json` of the modules contain something like `"main": "src/index.js"`, and the IDE even knows where it exactly should start, but as long as the auto-completion works, I am happy with anything) – Top-Master Apr 20 '19 at 06:21

0 Answers0