Type '{ maxHeight: ${string}%; opacity: number; }' is not assignable to type 'false…
- User
Type '{ maxHeight:
${string}%; opacity: number; }' is not assignable to type 'false | Value | RegisteredStyle | AnimatedInterpolation<string | number> | WithAnimatedObject | WithAnimatedArray<...>'. Types of property 'maxHeight' are incompatible. Type '${string}%' is not assignable to type 'number | Value | AnimatedInterpolation<string | number> | "auto" |${number}%| WithAnimatedObject'.ts(2322)const ExpandableView = ({ expanded = false, children }) => { const [height] = useState(new Animated.Value(0)); useEffect(() => { Animated.timing(height, { toValue: expanded ? 100 : 0, duration: 700, easing: Easing.out(Easing.exp), useNativeDriver: false }).start(); }, [expanded, height]); return ( <Animated.View style={{ maxHeight:
${height}%, opacity: 1 }}> {/* {interpolatedHeight} */} {children} </Animated.View> ); }; - Assistant
You are encountering this type error because the
maxHeightproperty in the style object expects a number, certain string literals (like "auto"), or an animation-related type, but you are providing it with a template literal${height}%, which it doesn't support.To fix this issue, you need to use an animated interpolation to convert your animated value
heightinto the correct format. Here's the revised code:javascript