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

Typescript: Cleanest way to put conditional Android/iOS types throughout file?

$
0
0

I'm using Typescript in my React Native app, and have different types/interfaces for various Android/iOS objects. For example, I have a receipt object that is of type AndroidReceipt on Android, and type iOSReceipt on iOS. The way I'm doing this now is

let receipt: Platform.OS === 'android' ? AndroidReceipt : iOSReceipt

Is there a simpler way to do this, rather than having to put a ternary statement in every time I want to enforce typing?


Viewing all articles
Browse latest Browse all 6287

Trending Articles



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