-
Notifications
You must be signed in to change notification settings - Fork 133
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
How to type remarkPlugins and rehypePlugins (Typescript) #86
Comments
I should add that if I ignore the typescript error with |
Hey @evantahler - I'll have to look into this one! It seems to be working ok with my examples of remark plugins, but that doesn't mean it works with all of them. |
i'm having the same issue. i believe it occurs whenever you try to specify options for a plugin using the Seems like |
Closed by #96 |
Thanks for the update... however, the newest versions still have the same problem for me:
|
i can confirm i'm also still getting type errors. looks like someone (me?) needs to actually dive into @jescalan can we reopen this issue? i'll have some time to work on this over the weekend. if you're assigning issues, happy to be assignee on this one. |
Done! Sorry for the slow movement here and appreciate the offer to help! |
It's now a ES module package which is making next-mdx-remote a bit unhappy, so we're supressing typescript type error on build as identified in hashicorp/next-mdx-remote#86
I'm going to close this out for now as the type definitions have been updated a bit with v3 earlier this year. Please feel free to reach out if you're still seeing issues, thanks! |
This #96 PR is messing things up for me. Now typescript is complaining my rehype plugins are incompatible because |
The same on my side ^^ |
Can y'all share what next-mdx-remote version you're using? v4 exposes types from the underlying |
Hum I am confused, I have tried again to build my project and it seems that the issue is gone. Maybe @mauroreisvieira can give you the version that causes issues. (On my side I use v3.0.8 right now) |
Yes, with version 3.0.8 I don't have issues, only with v4. |
If you can share a minimal reproduction in a codesandbox or a repo I'll take a look. |
Is the exact same code, but with different versions of I can try to prepare a Codesandbox. BTW I use: "dependencies": {
"@types/remark-prism": "^1.3.0",
"remark-prism": "^1.3.6"
} |
@mauroreisvieira ho yeah you are right v4 is breaking stuff, I have tried to upgrade.
with: "dependencies": {
"@mdx-js/loader": "^1.6.22",
"@next/mdx": "^12.1.0",
"next": "^12.0.8",
"next-mdx-remote": "^4.0.0",
"rehype-slug": "^4.0.1",
}, |
It looks like This is likely true for many third-party remark plugins. Please keep in mind v4 is a major upgrade and there were significant changes to the underlying MDX library, as well as the unified ecosystem of libraries. This isn't an issue with |
@BRKalow oh okay. So for all community plugins like that, we need to stick with the v3 then. Thanks for the clarifications! |
Thank you @BRKalow |
Well I found out the old issue I had: $ npm ls @mdx-js/mdx
├─┬ @next/mdx@12.1.0
│ └─┬ @mdx-js/loader@2.0.0
│ └── @mdx-js/mdx@2.0.0
└─┬ next-mdx-remote@3.0.8
└── @mdx-js/mdx@1.6.22 I have started to try $ npm ls @mdx-js/mdx
├─┬ @mdx-js/loader@1.6.22
│ └── @mdx-js/mdx@1.6.22
└─┬ next-mdx-remote@3.0.8
└── @mdx-js/mdx@1.6.22 deduped In conclusion, it better not use the two libs. 😉 |
@nos-nart you should check your dependencies with |
@Jule- I don't have
|
@nos-nart have you read my comment? Have you tried to run the command I gave you? |
Really appreciate everyone jumping in here to help out, but let's try to keep the tone friendly and welcoming please 😁 |
I apologize, I didn't mean to sound aggressive, just trying to be helpful and remind good practices IMHO in order to keep issues clear and to respect OS authors' and contributors' time. Really, no hard feelings. 😉 |
If anyone finds this topic I have found that typing the offending code like this works: import { Pluggable } from 'unified';
//...
mdxOptions: {
remarkPlugins: [
remarkGfm,
remarkHeadingId,
[
remarkToc,
{
heading: 'Contents',
ordered: true,
tight: true,
maxDepth: 3,
},
] as unknown as Pluggable<any[]>,
],
rehypePlugins: [
rehypeSlug,
rehypeAutolinkHeadings,
[rehypeExternalLinks, { target: '_blank' }] as unknown as Pluggable<
any[]
>,
],
}, |
this is a temp fix, related issue: hashicorp/next-mdx-remote#86
I'm very excited for v2.x.x of
next-mdx-remote
and gaining Typescript support!Trying out v2.0.1, I cannot figure out how to properly type the
remarkPlugins
andrehypePlugins
options forrenderToString
.You can see how we use it for www.grouparoo.com here https://github.com/grouparoo/www.grouparoo.com/blob/master/utils/mdxUtils.ts#L19-L22
And then later we:
Which yields the very long error:
Any hints on how to type this properly?
Thanks!
The text was updated successfully, but these errors were encountered: