При создании ссылки в компоненте React Native Typescript жалуется на это, если вы не указали правильный тип.
image = React.createRef();
state = {
x: new Animated.Value(0),
y: new Animated.Value(0),
};
render() {
const {x, y} = this.state;
const imageStyle = {left: x, top: y};
return (
<Animated.View
ref={this.image} // I got warning message here
{...this.responder}
style={[styles.draggable, imageStyle]}>
{this.props.children}
</Animated.View>
)
}
const styles = StyleSheet.create({
draggable: {
position: 'absolute',
height: itemWidth,
width: itemWidth,
},
});
Я получил это предупреждение
Тип '{children: ReactNode; style: ({left: Value; top: Value;} | {position: "absolute"; высота: число; ширина: число;}) []; ток: неизвестен; ref: RefObject; } 'нельзя назначить типу IntrinsicAttributes & AnimatedProps & {children ?: ReactNode; }». Свойство ref не существует для типа IntrinsicAttributes & AnimatedProps & {children ?: ReactNode; } '
createRef
строка должна выглядеть примерно так: image = React.createRef<some_type>();
Но я не знаю, как создать эту some_type