Reputation: 40624
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?
Upvotes: 1
Views: 822
Reputation: 40624
I finally fixed it by changing transitionStyles
to
const transitionStyles: { [id: string]: React.CSSProperties } = {
entering: { opacity: 1 },
entered: { opacity: 0 },
};
Upvotes: 5