我正在使用带有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
}
});这里我漏掉了什么?
发布于 2019-05-10 22:43:18
为props定义一个接口并注释函数参数似乎是可行的。
interface Props {
duration: number;
hiddenOffset: number;
}
const FadeIn = posed.div({
visible: {
opacity: 1,
scale: 1,
x: 0,
y: 0,
transition: (props: Props) => ({ duration: props.duration })
},
hidden: {
opacity: 0,
scale: 0.8,
x: (props: Props) => props.hiddenOffset,
y: 10
}
});https://stackoverflow.com/questions/56060372
复制相似问题