question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typescript type error when using interpolateColors

See original GitHub issue

Description

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

  1. Create a new react component with typescript
  2. Add an animation
  3. 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:closed
  • Created 3 years ago
  • Reactions:7
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
wilq32-pwitkowskicommented, Nov 2, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found