-
Notifications
You must be signed in to change notification settings - Fork 3.5k
feat: add generic types for parser and renderer output #3722
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -96,10 +96,10 @@ export class _Parser { | |||
} | |||
case 'text': { | |||
let textToken = token; | |||
let body = this.renderer.text(textToken); | |||
let body = this.renderer.text(textToken) as string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This as string
seems like the types are wrong. Is there a way to improve it so we don't need the assertion 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed because the renderer is generic so at this point this.renderer.test()
could return any type. We are assuming that the RendererOutput applies to all renderer functions so the user will have to change every function (including this one) if they want to return something other than a string. The correct way to type this would be to have a generic param for every renderer function. I feel like that is a bit overkill.
@@ -17,9 +17,9 @@ export function _getDefaults(): MarkedOptions { | |||
walkTokens: null, | |||
}; | |||
} | |||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | |||
export let _defaults: MarkedOptions<any, any> = _getDefaults(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why any
? Is that because we don't want to pass in generic types to _getDefaults()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we mark this as anything else then _defaults would have to stay that type. But because we can specify different types for some options this has to be any because it can be anything.
# [16.1.0](v16.0.0...v16.1.0) (2025-07-17) ### Features * add generic types for parser and renderer output ([#3722](#3722)) ([39a0ee3](39a0ee3))
Marked version: 16.0.0
Description
Add Generic types for parser and renderer output. This allows for parsers that output something other than an html string.
See UziTech/marked-html-renderer#9 for an example on how this can be used to output HTML elements.
Contributor
Committer
In most cases, this should be a different person than the contributor.