1

Here is my code:

 renderSoundWave = () => {
    const defaultStyle = {
      opacity: 1,
      transition: `opacity ${DURATION}ms ease-in-out`,
    }

    const transitionStyles = {
      entering: { opacity: 1 },
      entered:  { opacity: 0 },
    };
    return (

    <Transition timeout={DURATION} in={this.animate}>
      {(state) => (
        <div className={styles.soundWaves}
             style={{ ...defaultStyle, ...transitionStyles[state]}}> {/* Error here! */
          <SoundWaves/>
        </div>
        )}
    </Transition>
      );
  }

I want to use Transition in react-transition-group to animate the icon SoundWave.

However I am getting this error:

error TS7017: Element implicitly has an 'any' type because type '{ entering: { opacity: number; }; entered: { opacity: number; }; }' has no index signature.

The error points to ...transitionStyles[state] above

I don't understand why this error is thrown. What is causing this type error?

Anthony Kong
  • 37,791
  • 46
  • 172
  • 304

1 Answers1

5

I finally fixed it by changing transitionStyles to

const transitionStyles: { [id: string]: React.CSSProperties } = {
  entering: { opacity: 1 },
  entered:  { opacity: 0 },
};
Anthony Kong
  • 37,791
  • 46
  • 172
  • 304