If I use the example code from here in a standalone TypeScript file, then it works fine.
import { Marked } from "marked";
import { markedHighlight } from "marked-highlight";
import hljs from 'highlight.js';
const marked = new Marked(
markedHighlight({
langPrefix: 'hljs language-',
highlight(code, lang, info) {
const language = hljs.getLanguage(lang) ? lang : 'plaintext';
return hljs.highlight(code, { language }).value;
}
})
);
marked.parse(`
\`\`\`javascript
const highlight = "code";
\`\`\`
`);
If I add the same code into extension.ts of a VSCode extension, then I get this error:
Argument of type 'import("/home/foobar/node_modules/marked/lib/marked", { with: { "resolution-mode": "import" } }).MarkedExtension' is not assignable to parameter of type 'import("/home/foobar/node_modules/marked/lib/marked").MarkedExtension'.
Types of property 'extensions' are incompatible.
Type 'import("/home/foobar/node_modules/marked/lib/marked", { with: { "resolution-mode": "import" } }).TokenizerAndRendererExtension[] | null | undefined' is not assignable to type 'import("/home/foobar/node_modules/marked/lib/marked").TokenizerAndRendererExtension[] | null | undefined'.
Type 'import("/home/foobar/node_modules/marked/lib/marked", { with: { "resolution-mode": "import" } }).TokenizerAndRendererExtension[]' is not assignable to type 'import("/home/foobar/node_modules/marked/lib/marked").TokenizerAndRendererExtension[]'.
Type 'import("/home/foobar/node_modules/marked/lib/marked", { with: { "resolution-mode": "import" } }).TokenizerAndRendererExtension' is not assignable to type 'import("/home/foobar/node_modules/marked/lib/marked").TokenizerAndRendererExtension'.
Type 'TokenizerExtension' is not assignable to type 'TokenizerAndRendererExtension'.
Type 'TokenizerExtension' is not assignable to type 'TokenizerExtension & RendererExtension'.
Type 'import("/home/foobar/node_modules/marked/lib/marked", { with: { "resolution-mode": "import" } }).TokenizerExtension' is not assignable to type 'import("/home/foobar/node_modules/marked/lib/marked").TokenizerExtension'.
Types of property 'start' are incompatible.
Type 'import("/home/foobar/node_modules/marked/lib/marked", { with: { "resolution-mode": "import" } }).TokenizerStartFunction | undefined' is not assignable to type 'import("/home/foobar/node_modules/marked/lib/marked").TokenizerStartFunction | undefined'.
Type 'import("/home/foobar/node_modules/marked/lib/marked", { with: { "resolution-mode": "import" } }).TokenizerStartFunction' is not assignable to type 'import("/home/foobar/node_modules/marked/lib/marked").TokenizerStartFunction'.
The 'this' types of each signature are incompatible.
Type 'import("/home/foobar/node_modules/marked/lib/marked").TokenizerThis' is not assignable to type 'import("/home/foobar/node_modules/marked/lib/marked", { with: { "resolution-mode": "import" } }).TokenizerThis'.
The types of 'lexer.options.extensions' are incompatible between these types.
Type '{ renderers: { [name: string]: import("/home/foobar/node_modules/marked/lib/marked").RendererExtensionFunction; }; childTokens: { [name: string]: string[]; }; inline?: import("/home/foobar/node_modules/marked/lib/marked").TokenizerExtensionFunction[] | undefined; block?: import("/home/...' is not assignable to type '{ renderers: { [name: string]: import("/home/foobar/node_modules/marked/lib/marked", { with: { "resolution-mode": "import" } }).RendererExtensionFunction; }; childTokens: { [name: string]: string[]; }; inline?: import("/home/foobar/node_modules/marked/lib/marked", { with: { "resolution-mode...'.
Type '{ renderers: { [name: string]: import("/home/foobar/node_modules/marked/lib/marked").RendererExtensionFunction; }; childTokens: { [name: string]: string[]; }; inline?: import("/home/foobar/node_modules/marked/lib/marked").TokenizerExtensionFunction[] | undefined; block?: import("/home/...' is not assignable to type '{ renderers: { [name: string]: import("/home/foobar/node_modules/marked/lib/marked", { with: { "resolution-mode": "import" } }).RendererExtensionFunction; }; childTokens: { [name: string]: string[]; }; inline?: import("/home/foobar/node_modules/marked/lib/marked", { with: { "resolution-mode...'.
Types of property 'renderers' are incompatible.
Type '{ [name: string]: import("/home/foobar/node_modules/marked/lib/marked").RendererExtensionFunction; }' is not assignable to type '{ [name: string]: import("/home/foobar/node_modules/marked/lib/marked", { with: { "resolution-mode": "import" } }).RendererExtensionFunction; }'.
'string' index signatures are incompatible.
Type 'import("/home/foobar/node_modules/marked/lib/marked").RendererExtensionFunction' is not assignable to type 'import("/home/foobar/node_modules/marked/lib/marked", { with: { "resolution-mode": "import" } }).RendererExtensionFunction'.
The 'this' types of each signature are incompatible.
Type 'import("/home/foobar/node_modules/marked/lib/marked", { with: { "resolution-mode": "import" } }).RendererThis' is not assignable to type 'import("/home/foobar/node_modules/marked/lib/marked").RendererThis'.
The types of 'parser.options.tokenizer' are incompatible between these types.
Type 'import("/home/foobar/node_modules/marked/lib/marked", { with: { "resolution-mode": "import" } }).Tokenizer | null | undefined' is not assignable to type 'import("/home/foobar/node_modules/marked/lib/marked").Tokenizer | null | undefined'.
Type 'import("/home/foobar/node_modules/marked/lib/marked", { with: { "resolution-mode": "import" } }).Tokenizer' is not assignable to type 'import("/home/foobar/node_modules/marked/lib/marked").Tokenizer'.
Types of property 'lexer' are incompatible.
Type 'import("/home/foobar/node_modules/marked/lib/marked", { with: { "resolution-mode": "import" } }).Lexer' is not assignable to type 'import("/home/foobar/node_modules/marked/lib/marked").Lexer'.
Types have separate declarations of a private property 'tokenizer'.ts(2345)
The error is coming from the argument of new Marked(...)
What's happening here, and how can I fix it?