我正在使用带有react-pose 的TypeScript,并且需要定义道具的类型。这是我刚从create-react-app
3.0.1 版本开始的应用程序。
我不断收到错误Parameter 'props' implicitly has an 'any' type.
我试过在 div 上定义类型,类似于styled-components
:
const FadeIn = posed.div<{ duration: number; hiddenOffset: number }>({
visible: {
opacity: 1,
scale: 1,
x: 0,
y: 0,
transition: { duration: props => props.duration }
},
hidden: {
opacity: 0,
scale: 0.8,
x: props => props.hiddenOffset,
y: 10
}
});
我还尝试定义一个组件来代替posed.div
:
const FadeInContainer: React.FC<{
duration: number;
hiddenOffset: number;
}> = props => {
return <div {...props} />;
};
并通过它:
const FadeIn = posed(FadeInContainer)({
visible: {
opacity: 1,
scale: 1,
x: 0,
y: 0,
transition: { duration: props => props.duration }
},
hidden: {
opacity: 0,
scale: 0.8,
x: props => props.hiddenOffset,
y: 10
}
});
我在这里想念什么?