Closed tandrasi closed 1 month ago
What TS version you are using? I didn't add intentionally explicity return of type for components based on article: https://www.totaltypescript.com/jsx-element-vs-react-reactnode.
You should almost never use
JSX.Element
orReact.ReactElement
in your code. They're types used internally by TypeScript to represent the return type of JSX expressions. Instead, useReact.ReactNode
to type the children of your components. I'd also suggest not annotating the return types of your components to avoid confusion - but if you're using TypeScript 5.1, go ahead.
I am wondering where the error lies. Is it on my side and I should explicitly add the type ‘ReactNode’ for all components, or is the problem somewhere else like a big incompatibility of TS versions, or the type of parent components or something else?!
I'm using TS 4.7.4.
Previously, you used TS 5.5.2+ and now you're on 5.6.3+.
I'm even on React 17, but you have been using React 18 on v1 and v2.
I honestly feel something is not right with the exports. I have used loads of packages, and this is the only one that exhibits this problem.
Take a look at "fixedForwardRef". If you change its signature to the following, you will see the same error as me on your end in various places, like "app.tsx"
function fixedForwardRef<T, P = {}>(props: P & RefAttributes<T>): ReactNode {
// @ts-ignore
return forwardRef(render) as any;
}
@loba-b I've had another read of that link you sent and indeed I think it's a TypeScript version issue.
In TypeScript versions before 5.1, you can't use React.ReactNode in one specific case - typing the return type of a component.
For compatibility between TypeScript versions, may I suggest changing the return types from React.ReactNode to React.ReactElement?
Hi @tandrasi thank you for your support. I'll check it out, but I'm also thinking of removing the types for the returned component in fixedForwardRef. In the other component I didn't add such types because of the article, but for fixedForwardRef I found the solution online and didn't notice that there is type.
@tandrasi I think I have fixed the problem. I've removed the fixedForwardRef
and am passing the ref in the props in the standard way, so I'm still not adding the component type explicitly, so it should work correctly for TS4 and TS5. I'll run more tests today and if everything is fine, I'll implement the new version.
Thanks! In case you're committing a new version, I won't be able to check it out until Monday. Appreciate your work!
I have just released a new version @2.0.3
. Please test it when you can and please let me know if it is ok.
Hi, I just upgraded to version 2.0.2 from 1.0.3 and everything else being equal, I get the following error:
I have followed the upgrade steps and made the relevant updates: