我正试图将TypeScript集成到我们的项目中,到目前为止,我偶然发现了一个关于styled-components库的问题.
考虑这个组件
import * as React from "react";
import styled from "styled-components/native";
import { TouchableOpacity } from "react-native";
// -- types ----------------------------------------------------------------- //
export interface Props {
onPress: any;
src: any;
width: string;
height: string;
}
// -- styling --------------------------------------------------------------- //
const Icon = styled.Image`
width: ${(p: Props) => p.width};
height: ${(p: Props) => p.height};
`;
class TouchableIcon extends React.Component<Props> {
// -- default props ------------------------------------------------------- //
static defaultProps: Partial<Props> = {
src: null,
width: "20px",
height: "20px"
};
// -- render -------------------------------------------------------------- //
render() {
const { onPress, src, width, height } = this.props;
return (
<TouchableOpacity onPress={onPress}>
<Icon source={src} width={width} height={height} />
</TouchableOpacity>
);
}
}
export default TouchableIcon;
下面的一行抛出3个错误,性质相同
键入{source:any;width:string;height:string;}不可转让
不完全确定这是什么以及如何修复它,我是否需要在Icon
或类似的东西上声明这些?
EDIT:类型脚本v2.6.1
,样式化组件v2.2.3