I have following component that mainly relies on Image from react-native
// @flow
import React from "react";
import { Image } from "react-native";
import { deviceWidth } from "../services/device";
type Props = {
width: number,
ratio: number
};
class RatioImage extends React.Component<Props> {
render() {
const { width, ratio, style, ...props } = this.props;
return (
<Image
{...props}
style={[
{
width: deviceWidth * (width / 100),
height: deviceWidth * (width / 100) * ratio
},
style
]}
/>
);
}
}
export default RatioImage;
I was able to type annotate my own props, but in example above style throws an error
[flow] property
style(Property not found in Props) const style: any
I know that in typescript I can just extend interface to Image one, is there something in flow that I can use in order to make my props inherit all types from Image somehow? How would I even import such types from react-native?
EDIT I found out about concept called intersection types and tried this
import { Image, type Image as ImageProps } from "react-native";
type Props = ImageProps & {
width: number,
ratio: number
};
but style is still throwing an error, although different one
[flow] property
style(Property cannot be accessed on any member of intersection type intersection Member 1: ImageProps Error: propertystyleProperty not found in React component Member 2: object type Error: propertystyleProperty not found in object type) const style: any
Image.propTypes.stylecould work: stackoverflow.com/a/44758937/851045 - Giraldi