-
-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type error reported by @typescript-eslint/no-unsafe-return
#10
Comments
Maybe related to #6 ? (now that React 19 has been released) |
This is an XY-problem. Your linter complains. The real problem is that there is a type error in This is indeed what I tried to fix in #6. As a workaround you can define the global JSX namespace yourself, do a type cast, or add an |
Oh ok, that would diverge from the types of
I think I'll stick with the type assertion workaround I mentioned in the original issue above: import { type JSX } from 'react';
toJsxRuntime(...) as JSX.Element |
To be clear, that's just a workaround though - does I can't observe the actual TS type error in my editor / on the command line via |
The JSX frameworks used to define the IMO we should not rely on the global JSX namespace anymore at all, but the team is in disagreement on this. Also even if we do, the problem is hard to resolve. If we can’t rely on the |
This project depends on JSX, which is why it uses the quite useful |
This comment has been minimized.
This comment has been minimized.
Thanks for the background!
@wooorm I'm guessing that you mean ae638ba, the recommendation in the Use section of the readme to use the following code: import type {JSX as Jsx} from 'react/jsx-runtime'
declare global {
namespace JSX {
type ElementClass = Jsx.ElementClass
type Element = Jsx.Element
type IntrinsicElements = Jsx.IntrinsicElements
}
} It seems like it's kind of ok, but it's a lot of code for common use cases, and the error DX is not great (finding the error first of all, and then finding out that it's not a bug but a separate setup requirement - to paste code in some file). Since there is the widespread removal of the global import { type JSX } from 'react';
toJsxRuntime<JSX>(...) Or maybe there are other options: I'm not sure whether this was considered somewhere (maybe already in #6, if I didn't understand completely yet), but would it be possible to retrieve the type from the passed So that no code would need to change, and the type is somehow retrieved from the function? import { toJsxRuntime } from 'hast-util-to-jsx-runtime';
import { Fragment } from 'react';
import { jsx, jsxs } from 'react/jsx-runtime';
toJsxRuntime(out, {
Fragment,
jsx, // Type retrieved from this `jsx` function
jsxs,
}); |
Initial checklist
Affected package
hast-util-to-jsx-runtime@2.3.2
Steps to reproduce
@typescript-eslint/no-unsafe-return
rule in some Node.js or Next.js project (eg. Next.js App Router project)hast-util-to-jsx-runtime
incomponents/CodeBlock.tsx
Reproduction (
typescript-eslint
Playground)Using a
as JSX.element
type assertion on the return value oftoJsxRuntime()
is a workaround for the issue:Actual behavior
Error with a "type error". The type error is not observable.
Expected behavior
No error
Runtime
node@22.11.0
Package manager
yarn@1.22.22
Operating system
macOS Sequoia 15.1.1
Build and bundle tools
other (please specify in steps to reproduce)
The text was updated successfully, but these errors were encountered: