Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6211

How to create typings alias in typescript the way we create dependency alias in babelrc?

$
0
0

TL;DR:

How to create typing alias in typescript the way we create dependency alias in babelrc?

The full question:

Let's say I am developing for iOS and web, and would like to write only one set of code. I am using React-Native and something that has an interface that is very similar to React-Native, for the sake of this question, let's call it Respond-Native(a made-up name).

In the project, I used a component called <Picker />. The Picker on Respond-Native(still the made-up library) has a property that is not present in React-Native called onSwipe.

But other than that, the rest of the interface is pretty much the same. Minute differences like this are all over Respond-Native.

And to make typing easier, I have two almost identical projects. The only thing that is different is that I added an alias to the .babelrc of the project that uses Respond-Native:

// .babelrc

{
  ...
  "plugins": [
    ...
    ["module-resolver", {
      "root": ["./"],
      "alias": {

        // the alias is here
        "react-native": "respond-native"

      }
    }]
  ]
}

However, when I write <Picker onChange={handleOnChange} onSwipe={handleOnSwipe} />, the editor does not know about the dependency alias and have no idea where the prop onSwipe comes from.

Sorry for the long build-up.

My question is, how can I do the same in creating typing alias (like I did in babelrc) so that VS Code would know which type declaration to use when checking types? (given that Respond-Native also has a Picker type/interface declared)


Viewing all articles
Browse latest Browse all 6211

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>