I am converting a React ponent into Typescript (*.ts) from JS. It is giving the error below "Type expected". How would I fix this?
const SisenseDashboard = () => {
const sisenseRef = React.useRef(null);
return (
<>
<Box
display="flex"
flexDirection="column"
alignItems="center"
marginBottom={2}
>
<h2>In-App Reporting</h2>
</Box>
<Box
ref={sisenseRef}
id="sisense-container"
className="sisense-demo"
></Box>
</>
);
};
I am converting a React ponent into Typescript (*.ts) from JS. It is giving the error below "Type expected". How would I fix this?
const SisenseDashboard = () => {
const sisenseRef = React.useRef(null);
return (
<>
<Box
display="flex"
flexDirection="column"
alignItems="center"
marginBottom={2}
>
<h2>In-App Reporting</h2>
</Box>
<Box
ref={sisenseRef}
id="sisense-container"
className="sisense-demo"
></Box>
</>
);
};
Share
Improve this question
edited Jan 29, 2023 at 11:13
Youssouf Oumar
46k16 gold badges100 silver badges104 bronze badges
asked Mar 29, 2022 at 17:38
mattsmith5mattsmith5
1,1334 gold badges48 silver badges106 bronze badges
0
1 Answer
Reset to default 23Make sure your ponent file extension is .tsx
and not .ts
. This should resolve your issue. Addinonnaly, you could tell TypeScript that your function is a React Functional Component, for example, with the help of the FC
type from React:
import {FC} from "react";
const SisenseDashboard : FC = () => {
const sisenseRef = React.useRef(null);
return (
<>
<Box
display="flex"
flexDirection="column"
alignItems="center"
marginBottom={2}
>
<h2>In-App Reporting</h2>
</Box>
<Box
ref={sisenseRef}
id="sisense-container"
className="sisense-demo"
></Box>
</>
);
};