-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fix the JSX runtime types in RunOptions #2465
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
* Function to generate an element in development mode. | ||
* @property {Jsx | null | undefined} [jsxs] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we at least use something like Function
?
We could also improve the hast-util-to-jsx-runtime
types?
Fixing the type error is nice, but removing all type errors around this, not so sure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could use Function
, or better: (type: any, props: any) => any
.
We should improve hast-util-to-jsx-runtime
, but personally I think this type isn’t worth having an extra dependency regardless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or better:
(type: any, props: any) => any
.
Right, and even better would be an even more correct type. We do know a lot about props and key. And at that point, it’s nice to have the more complex type defined and tested in a single place?
31b7a52
to
98c5f55
Compare
98c5f55
to
bbbfe2e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the breaking change happened in the other PR, but Fragment
and similar were types that were exposed from MDX. And now aren‘t.
The other PR only changed that they’re no longer exported from internal files. It could be considered breaking here. There’s not really a use for them anymore, but they can be defined as On the other hand, as a user I wouldn’t find it too bad if TypeScript forces me to make this change: - /**
- * @import {Fragment, Jsx} from '@mdx-js/mdx'
- */
-
- import * as runtime_ from 'react/jxs-runtime'
-
- const runtime = /** @type {{Fragment: Fragment, jsx: Jsx, jsxs: Jsx}} */ (
- /** @type {unknown} */ (runtime_)
- )
+ import * as runtime from 'react/jxs-runtime' |
I think we’ve had this conversation partially a couple times already, the gist of my stance is: generally, we have types for things. so why are we now removing types? |
I think we should aim at the following:
While (3) is great, I strongly believe we need to aim for (2) first. That’s what this PR solves. I don’t think any users are helped with types that prevent the user from using the code without type casting (to / from I doubt it’s useful, because users are typically supposed to pass in a known runtime, not define one. However, it is possible to use the following somewhat stricted types: /**
* @typedef {unknown} Fragment
*/
/**
* @callback Jsx
* @param {any} type
* @param {object} props
* @param {any} [key]
*/
/**
* @callback JsxDev
* @param {any} type
* @param {object} props
* @param {any} key
* @param {boolean} isStatic
* @param {object} [source]
* @param {object} [self]
*/
The problem with those types is that |
Why? I don‘t think we’ve done that before: implement an
I do think that people should be able to type check Also keep in mind that these types are from another project where this is important.
That sounds like something that can be solved? |
TypeScript is supposed to help users. Types that are wrong are significantly worse than types that are loose. What you call a simple workaround, I call an imperfect, but pragmatic solution. We actually do use
Sure, it’s nice, but the user is bound to the types of their JSX framework and MDX. They just import one thing and pass it to a function. They don’t have a say in how any of it is typed or implemented. I’m not saying stricter types are bad, I’m saying the status quo (incorrect types) is significantly worse than loose types.
I don’t see how, except for disabling |
I disagree.
I disagree, I think they do.
Facebook did not ship types. It was a
This is intentional: if we can get correct types from another place that is fine too.
We often implement solutions in the place where the problem originates, instead of patching intermediate packages?
|
`@types/react` now has types for `react/jsx-runtime` and `react/jsx-dev-runtime`. These types are not compatible with the types provided by `hast-util-to-jsx-runtime`, which are used by MDX. To resolve the issue, all runtime related options have been changed to `unknown`. Since the user is supposed to pass in whatever JSX runtime they imported, this should be sufficient. This fixes several type errors. An outdated workaround has been removed from the documentation. Closes #2463
bbbfe2e
to
facc3b4
Compare
Externally fixed, thanks! |
Initial checklist
Description of changes
@types/react
now has types forreact/jsx-runtime
andreact/jsx-dev-runtime
. These types are not compatible with the types provided byhast-util-to-jsx-runtime
, which are used by MDX.To resolve the issue, all runtime related options have been changed to
unknown
. Since the user is supposed to pass in whatever JSX runtime they imported, this should be sufficient. This removes the dependency onhast-util-to-jsx-runtime
.This fixes several type errors. An outdated workaround has been removed from the documentation.
Closes #2463