I've been encountering some unusual type errors in my TypeScript project with certain packages. For example:
'TimeAgo' cannot be used as a JSX component.
Its instance type 'ReactTimeago<keyof IntrinsicElements | ComponentType<{}>>' is not a valid JSX element.
The types returned by 'render()' are incompatible between these types.
Type 'React.ReactNode' is not assignable to type 'import("/home/user/app/node_modules/@types/react-bootstrap-table-next/node_modules/@types/react/index").ReactNode'.
Type '{}' is not assignable to type 'ReactNode'.
Interestingly, I don't encounter these type errors on my local Windows machine, but they persist on my Linux virtual machine. I have tried deleting and re-creating the project multiple times, cloning the repository, and reinstalling packages using different versions of Node, yet the same type errors keep popping up.
I have checked Node versions 12.18.3 and 16.13.1
Below is some information from my package.json file:
"react-timeago": "^6.2.1",
"react-custom-scrollbars": "^4.2.1",
"react-custom-scrollbars-2": "^4.4.0",
"react": "^17.0.2",
"next": "^12.1.1",
"@types/react-custom-scrollbars": "^4.0.10",
"@types/react-timeago": "^4.1.3",
"@types/react": "^17.0.44",
"typescript": "^4.3.5"
"@types/node": "^14.18.12",
These type errors seem to occur with basic custom components like:
MyTst.tsx
import TimeAgo from "react-timeago";
const Mytst = () => {
return (
<div>
<TimeAgo date={"02/02/2022"} />
</div>
);
};
export default Mytst;
The error also arises for react-custom-scrollbars-2. It appears that there might be an issue in correctly matching the types between the library containing the component and its associated @types files. Does anyone have any suggestions on how to resolve these type errors?