Skip to content
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

Types for this.parser don't match notes of v13 release because parser is omitted #3326

Closed
cascornelissen opened this issue Jun 13, 2024 · 3 comments · Fixed by #3339
Closed

Comments

@cascornelissen
Copy link

Marked version:
13.0.0

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Trying to migrate an extension by following the notes of the release results in code that's incompatible with the TypeScript types. The cause seems to be that RendererObject refers to RendererApi which is defined as Omit<_Renderer, "constructor" | "options" | "parser"> so parser is being omitted?

const extension: MarkedExtension = { // Added the explicit type here
  useNewRenderer: true,
  renderer: {
    heading(token) {
      // increase depth by 1
      const text = this.parser.parseInline(token.tokens);
      const level = token.depth;
      return `<h${level + 1}>${text}</h${level + 1}>`;
    }
  }
};

marked.use(extension);
image

Expected behavior
The example works as expected.

@UziTech
Copy link
Member

UziTech commented Jun 13, 2024

That is because the this that is passed in is a Renderer not a RendererObject.

The function signature in typescript should be

heading(this: Renderer, token: Tokens.Heading): string {

@cascornelissen
Copy link
Author

cascornelissen commented Jun 13, 2024

Based on the works as intended label I assume not, but is it not possible to type this correctly on the side of marked?

@UziTech
Copy link
Member

UziTech commented Jun 13, 2024

You are creating the function so you need to type it correctly. The function signature I provided is the way you would create the correctly typed function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants