React Native: platform specific import

Viewed 18

Got this weird situation. Building for react native and using a native package from Intercom. Importing it works fine when android or ios. But for the web (or node jest) it throws an error. So have to do some face-pattern "hacking" like this

utilities/Intercom/index.ios.ts

export { default } from '@intercom/intercom-react-native'

utilities/Tntercom/index.web.ts

export default function Intercom() {}

some file that uses Intercom

// @ts-ignore
import Intercom from '~/utilities/Intercom'

...

Intercom.logout() // no TS support

Not only does TS complain, but I also loses all types

Is there any other way to do platform specific import and keep the native types?

0 Answers
Related