-
Hello! I am writing a custom compiler for markdown AST. I can't figure out how to type type TTS = { input: Array<string>; frontmatter: Record<string, string> };
declare module "unified" {
interface CompileResultMap {
TTS: TTS;
}
}
function ttsCompiler(
this: Processor<undefined, undefined, undefined, Root, TTS>
) {
this.compiler = (ast) => ({ input: [], frontmatter: {} });
}
const ast = await unified()
.use(remarkParse)
.use(remarkMDX)
.use(remarkFrontmatter)
// ^^^^^^^^^^^^^^^^^^^ this gives the following error
.use(ttsCompiler)
.process(rawMDX);
I assume that's because I can't type export default function remarkStringify(options) {
/** @type {Processor} */
// @ts-expect-error: TS in JSDoc generates wrong types if `this` is typed regularly.
const self = this When I assign Also, can I somehow make the output to be of the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 14 replies
-
Hey! Use This is a bit weird because: a) the b) TS for JS is buggy with the
IIRC what you want should indeed happen. |
Beta Was this translation helpful? Give feedback.
-
Why are you even trying to create a custom compiler that returns a non-string result?
Yes, by typing your |
Beta Was this translation helpful? Give feedback.
Using
index.ts
and latest packages, VS code does show that type error.I recommend adding at
@ts-expect-error
:const ttsCompiler: Plugin<[], Root, CompiledArticle> = function () { + // @ts-expect-error this.compiler = compiler;
Or cast:
The
unified
types seem to tie a) what the current compiler could be, with b) the new compiler intended to be set.