I have this very simple function that I am trying to test with Flow:
type Props = {
width: string | number,
};
function fun({
width = '30em',
}: Props) {
return width;
}
The problem is that I get this error:
8: width = '30em',
^ number. This type is incompatible with
8: width = '30em',
^ string
8: width = '30em',
^ string. This type is incompatible with
8: width = '30em',
^ number
8: width = '30em',
^ string. This type is incompatible with
8: width = '30em',
^ number
I wonder what I'm doing wrong ... This method works fine:
type Props = {
width: string | number,
};
function fun(props: Props) {
const {
width = '30em',
} = props;
return width;
}
And this syntax inside function arguments is supported because:
type Props = {
width: string,
};
function fun({ width = '30em' }: Props) {
return width;
}
This works great.
Ideas?
source
share