I am trying to use Typography component from material-ui with TypeScript, but I am getting this weird error
TypeScript error: Type 'string' is not assignable to type 'ComponentClass<HTMLAttributes<HTMLElement>, any> | FunctionComponent<HTMLAttributes<HTMLElement>> | undefined'. TS2322
8 | }
9 | export default ({ text, date }: Props) => (
> 10 | <Typography component="p" gutterBottom>
| ^
11 | {text && <span>{text}: </span>}
12 | <FormattedDate value={date} />
13 |
Here's how my component looks like
import React from 'react';
import { FormattedDate, FormattedTime } from 'react-intl';
import Typography from '@material-ui/core/Typography';
interface Props {
date: Date;
text?: string;
}
export default ({ text, date }: Props) => (
<Typography component="p" gutterBottom>
{text && <span>{text}: </span>}
<FormattedDate value={date} />
<FormattedTime value={date} />
</Typography>
);
I am not able to understand why "p" is not an acceptable value for component prop. I tried it with "h1" and "h2" which fails in the same way and apparently, the official demo also uses the string.
Is there anything I am missing?, I don't want to ignore this with // @ts-ignore, but want to fix this.