I have this piece of code:
protected getCardContent = (message: string): JSX.Element => {
const { placeInfo } = this.props;
const TouchableComponent = Platform.OS === 'ios' ? TouchableOpacity : TouchableNativeFeedback
return (
<View>
<Text>{placeInfo.name}'s phone number:</Text>
<TouchableComponent onPress={() => {}}>
<Text>{placeInfo.phoneNumber}</Text>
</TouchableComponent>
</View>
)
}
When calling this.getCardContent
in my render method it works on both iOS and Android devices; however, TS complains saying:
const TouchableComponent: typeof TouchableOpacity | typeof TouchableNativeFeedback
JSX element type 'TouchableComponent' does not have any construct or call signatures.
Is it because TouchableComponent
can be of either constructor type, thus TS doesn't explicitly know what the instantiated type is? What would be a better way to solve this issue that works with the TS compiler?