Closed xsjcTony closed 4 months ago
Fixed the issue here, but your plugin types are wrong too. They are for markdown-it v13. You need to change imports:
import type { RenderRule } from 'markdown-it/lib/renderer.mjs';
...
const renderToken: RenderRule = ...
upstream issue - https://github.com/Swatinem/rollup-plugin-dts/issues/311
Sorry I'm not familiar with markdown-it, so you mean @types/markdown-it contains both types for v13 and v14 and I'm using the v13 part?🤣
No. That part is also throwing error in the stackblitz example you've provided. I'm just suggesting how to fix errors inside that plugins/externalLinkIcon.ts file
PS: you don't need a plugin for external link icon, it's now builtin https://vitepress.dev/reference/default-theme-config#externallinkicon
That's a bit confusing, because I installed the v14 of @types/markdown-it
, hence I'm assuming below are the same, as they are just different way to import the same thing.
import type { Renderer } from 'markdown-it';
type RenderRule = Renderer.RenderRule;
import type { RenderRule } from 'markdown-it/lib/renderer.mjs';
PS: yeah I'm aware there's a built-in one, but I just want to use my own icon there.
And I believe I need to fix below as per your suggestion as well, even I don't understand why is that🤦♀️ From
import type { ParserBlock } from 'markdown-it';
type RuleBlock = ParserBlock.RuleBlock;
To
import type { RuleBlock } from 'markdown-it/lib/parser_block.mjs';
I believe PluginSimple
remains the same like this?
import type { PluginSimple } from 'markdown-it';
hence I'm assuming below are the same, as they are just different way to import the same thing.
no
there is no Renderer
type exported from markdown-it's default entrypoint.
I believe
PluginSimple
remains the same like this?
yeah
You can just type and check. If it doesn't show errors like this, then it's okay:
Module '"markdown-it"' has no exported member 'Renderer'. Did you mean to use 'import Renderer from "markdown-it"' instead? ts(2614)
I see. However my IDE can pick it up and seems vue-tsc
can as well.
But I agree with you, the CJS build of @types/markdown-it
is a mess. If I use the ESM dts file, it's very clear which one I should import, but it's confusing that CJS build is exporting things differently from the ESM build🤣
Thanks for the suggestions overall, I've fixed those.
Indeed it's confusing, wondering if there's a way I can default it to import from ESM dts file instead of CJS, without having to add .mjs
after the filename
I see. However my IDE can pick it up and seems vue-tsc can as well.
Ah, sorry. I was getting those errors because I changed moduleResolution to nodenext in your example's tsconfig. Right, with moduleResolution node it will resolve to CJS export and it will not throw any error on import type { Renderer } from 'markdown-it'
Indeed it's confusing, wondering if there's a way I can default it to import from ESM dts file instead of CJS, without having to add .mjs after the filename
You can try setting your moduleResolution to bundler.
Yes, I've tried it as it works both ways with the new fix.
You can try setting your moduleResolution to bundler.
Yeah that works. Thanks for the suggestion!
Also thanks for the quick fix💖 Appreciate that.
Describe the bug
I'm encountering the type issue of
markdown-it
when using themarkdown.config
property in the vitepress config file. I have 3 plugins, all with issues. I reproduced the simplest one in the reproduction below. I believe they have the same problem. I'll log all the issues I'm having in Additional Context field, but please have a look at the reproduction below, thanks.Reproduction
https://stackblitz.com/edit/vite-qvbnhu?file=docs%2F.vitepress%2Fconfig.ts
Expected behavior
No error is raised.
System Info
Additional context
Validations