title: Account for multiple peer dependency versions in react-typescript library
body: <p>I am converting my react component library <a href="https://github.com/slutske22/react-esri-leaflet" rel="nofollow noreferrer">react-esri-leaflet</a> over to typescript.  The library requires the user to install react-leaflet as a peerDependency, and it provides support for react-leaflet version 3 (RLV3), as well as react-leaflet version 2 (RLV2).  For the default components, I can simply do</p>
  <pre class="lang-js prettyprint-override"><code>import { createLayerComponent } from 'react-leaflet'
  </code></pre>
  <p>But if the user wants to use the components that are compatible for RLV2, they can import those components separately (feel free to look at the library docs to see how).  Most of the RLV2 components start with something like</p>
  <pre class="lang-js prettyprint-override"><code>import { withLeaflet, MapControl } from 'react-leaflet'
  </code></pre>
  <p>While converting over to typescript, this throws an error.  While developing this library, my install of react-leaflet installs the newest version. <code>withLeaflet</code> and <code>MapControl</code> no longer exist in that version.</p>
  <p>To solve that problem, I followed the advice in <a href="https://stackoverflow.com/a/56495895/12010984">this answer</a> to &quot;Two versions of same npm package in Node application&quot;. This allows me to treat RLV2 as a separate package in my source code by aliasing it to <code>'react-leaflet-v2'</code>, and I can do</p>
  <pre class="lang-js prettyprint-override"><code>import { withLeaflet, MapControl } from 'react-leaflet-v2'
  </code></pre>
  <p>Great, now typescript is happy, and I can import the appropriate version of react-leaflet to the appropriate component and the typings are correct.  However, when I compile back to js using <code>tsc</code>, the package name being used in my V2 components is still <code>'react-leaflet-v2'</code>.</p>
  <p>The problem is that the end-user of the library is going to be using <em>either</em> RLV2 or RLV3, and its going to simply be called <code>'react-leaflet'</code> in their project.  The compiled files of the library need to be able to find <code>'react-leaflet'</code>, not some alias, regardless of the version they're using.</p>
  <p>How can I maintain type safety in development for both dependency versions, but allow my users to not worry about it, meaning just install the version of react-leaflet that they want to use, import the correct components from the library, and have the components find the <code>'react-leaflet'</code> dependency in their project?  Is it possible to tell <code>tsc</code> to rename <code>'react-leaflet-v2'</code> to <code>'react-leaflet'</code> when compiling?  Is there another solution?</p>