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

TypeScript complains about conditionally assigning class: JSX element type 'TouchableComponent' does not have any construct or call signatures

$
0
0

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?


Viewing all articles
Browse latest Browse all 6211

Trending Articles



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