Typescript type error when using interpolateColors
See original GitHub issueDescription
Typescript displays the following error message when using interpolateColors on the color property of an Animated.Text Component:
No overload matches this call.
Overload 1 of 2, '(props: AnimateProps<TextStyle, TextProps> | Readonly<AnimateProps<TextStyle, TextProps>>): Text', gave the following error.
Type '{ color: Animated.Node<number>; }' is not assignable to type 'StyleProp<AnimateStyle<TextStyle>>'.
Types of property 'color' are incompatible.
Type 'AnimatedNode<number>' is not assignable to type 'string | unique symbol | AnimatedNode<string | unique symbol | undefined> | undefined'.
Type 'AnimatedNode<number>' is not assignable to type 'AnimatedNode<string | unique symbol | undefined>'.
Overload 2 of 2, '(props: AnimateProps<TextStyle, TextProps>, context: any): Text', gave the following error.
Type '{ color: Animated.Node<number>; }' is not assignable to type 'StyleProp<AnimateStyle<TextStyle>>'.
Types of property 'color' are incompatible.
Type 'AnimatedNode<number>' is not assignable to type 'string | unique symbol | AnimatedNode<string | unique symbol | undefined> | undefined'.
Type 'AnimatedNode<number>' is not assignable to type 'AnimatedNode<string | unique symbol | undefined>'
Steps To Reproduce
- Create a new react component with typescript
- Add an animation
- Use interpolateColors to change the (background) color of an animated component
Snack or minimal code example
import React from 'react';
import Animated, { interpolateColors, Value } from 'react-native-reanimated';
export default class ReanimatedTest extends React.Component {
state: { x: any };
constructor(props: any) {
super(props);
this.state = {
x: new Value(0),
};
}
render() {
return (
<Animated.Text
style={{
color: interpolateColors(this.state.x, {
inputRange: [0, 1],
outputColorRange: ['rgba(255, 0, 0, 1)', 'rgba(0, 255, 0, 1)'],
}),
}}
>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quos,
similique?
</Animated.Text>
);
}
}
Package versions
- React: 16.13.1
- React Native: 39.0.3
- React Native Reanimated: 1.13.0
Issue Analytics
- State:
- Created 3 years ago
- Reactions:7
- Comments:9 (3 by maintainers)
Top Results From Across the Web
React Native - Typescript issue - Stack Overflow
I think currently they are moving to the v2 of react-native-redash, and some functions are not where they are used to be. However,...
Read more >Developers - Typescript type error when using interpolateColors -
Typescript displays the following error message when using interpolateColors on the color property of an Animated.Text Component:
Read more >[TypeScript] Getting a type error when trying to run my program
Hello, I am following this tutorial (https://www.youtube.com/watch?v=k2h7usLLBhY) and I am encountering and issue in the animated-chechkbox ...
Read more >Cannot use import statement outside a module [React ...
This error might be raised when using either JavaScript or TypeScript in the back-end. So you could be working on the client side...
Read more >interpolateColors | React Native Reanimated
interpolateColors (node, { // Input range for the interpolation. Should be monotonically increasing. inputRange: [nodeOrValue, ...],
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For anyone having problem with this, temporary solution might be to
interpolateColors(this.state.x, { inputRange: [0, 1], outputColorRange: ['rgba(255, 0, 0, 1)', 'rgba(0, 255, 0, 1)'], })
go with
interpolateColors(this.state.x, { inputRange: [0, 1], outputColorRange: ['rgba(255, 0, 0, 1)', 'rgba(0, 255, 0, 1)'], }) as any
Not perfect, but until it’s fixed it just makes TS ignore this error.
https://github.com/software-mansion/react-native-reanimated/pull/1467