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

Custom TouchableOpacity from Pressable TypeScript error

$
0
0

Have this custom TouchableOpacity function component, but for the style prop I'm getting a TS error

import { StyleSheet, Pressable, PressableProps, GestureResponderEvent } from 'react-native';export default function TouchableOpacity(props: PressableProps) {  const { style, onPress, children } = props;  return (<Pressable      onPress={(event: GestureResponderEvent) => {        onPress?.(event);      }}      style={({ pressed }) => [style, pressed ? styles.buttonPressedOpacity : null]}>      {children}</Pressable>  );}const styles = StyleSheet.create({  buttonPressedOpacity: {    opacity: 0.5,  },});

Here is the complete TS complaint:

TS2322: Type '({ pressed }: PressableStateCallbackType) =>(StyleProp | ((state: PressableStateCallbackType) =>StyleProp<...>) | { ...; })[]' is not assignable to type'StyleProp | ((state: PressableStateCallbackType) =>StyleProp)'.   Type '({ pressed }:PressableStateCallbackType) => (StyleProp | ((state:PressableStateCallbackType) => StyleProp<...>) | { ...; })[]' is notassignable to type '(state: PressableStateCallbackType) =>StyleProp'.     Type '(StyleProp | ((state:PressableStateCallbackType) => StyleProp) | { opacity:number; })[]' is not assignable to type 'StyleProp'.      Type '(StyleProp | ((state: PressableStateCallbackType) => StyleProp) | { opacity:number; })[]' is not assignable to type 'RecursiveArray<ViewStyle |Falsy | RegisteredStyle>'.         The types returned by'pop()' are incompatible between these types.           Type'StyleProp | ((state: PressableStateCallbackType) =>StyleProp) | { opacity: number; }' is not assignable totype 'ViewStyle | Falsy | RegisteredStyle |RecursiveArray<ViewStyle | Falsy | RegisteredStyle> |readonly (ViewStyle | ... 1 more ... | RegisteredStyle<...>)[]'.            Type '(state: PressableStateCallbackType) => StyleProp' is not assignable to type 'ViewStyle | Falsy |RegisteredStyle | RecursiveArray<ViewStyle | Falsy |RegisteredStyle> | readonly (ViewStyle | ... 1 more ... |RegisteredStyle<...>)[]'. index.d.ts(542, 5): The expected type comesfrom property 'style' which is declared here on type'IntrinsicAttributes & PressableProps & RefAttributes'


Viewing all articles
Browse latest Browse all 6287

Trending Articles



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