I have this very simple function I'm trying to validate with Flow:
// @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 other way works fine:
// @flow
type Props = {
width: string | number,
};
function fun(props: Props) {
const {
width = '30em',
} = props;
return width;
}
And this syntax inside function arguments seem supported because:
// @flow
type Props = {
width: string,
};
function fun({ width = '30em' }: Props) {
return width;
}
This works just fine.
Ideas?