shikijs / twoslash

You take some Shiki, add a hint of TypeScript compiler, and 🎉 incredible static code samples
https://shikijs.github.io/twoslash/
MIT License
1.08k stars 53 forks source link

Type error when using remark-shiki-twoslash #167

Closed GoodbyeNJN closed 2 years ago

GoodbyeNJN commented 2 years ago

Example code:

unified()
  .use(remarkParse)
  .use(remarkShikiTwoslash)
  .use(remarkRehype)
//     ^^^^^^^^^^^^
//     Argument of type 'Plugin<[] | [Processor<any, any, any, any>, (Options | undefined)?] | [null | undefined, (Options | undefined)?] | [Options], Root, Root>' is not assignable to parameter of type 'Preset | PluggableList'.ts(2345)
  .use(rehypeStringify)
  .process("# Hello World");

According to the unified document, remarkShikiTwoslash function should be declared as a Plugin type, which returns a Transformer type, so that subsequent use methods can correctly infer the type.

Source code from unified: https://github.com/unifiedjs/unified/blob/main/index.d.ts#L527