feat: add generic types for parser and renderer output#3722
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
| 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.
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.
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.
| }; | ||
| } | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| export let _defaults: MarkedOptions<any, any> = _getDefaults(); |
There was a problem hiding this comment.
Why any? Is that because we don't want to pass in generic types to _getDefaults()?
There was a problem hiding this comment.
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))
This PR contains the following updates: | Package | Change | Age | Confidence | |---|---|---|---| | [marked](https://marked.js.org) ([source](https://github.com/markedjs/marked)) | [`15.0.12` -> `16.2.0`](https://renovatebot.com/diffs/npm/marked/15.0.12/16.2.0) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>markedjs/marked (marked)</summary> ### [`v16.2.0`](https://github.com/markedjs/marked/releases/tag/v16.2.0) [Compare Source](markedjs/marked@v16.1.2...v16.2.0) ##### Features - add def token in tokens and renderer ([#​3745](markedjs/marked#3745)) ([0769124](markedjs/marked@0769124)) ### [`v16.1.2`](https://github.com/markedjs/marked/releases/tag/v16.1.2) [Compare Source](markedjs/marked@v16.1.1...v16.1.2) ##### Bug Fixes - fix multiline list item adds extra newline to raw ([#​3735](markedjs/marked#3735)) ([e76453e](markedjs/marked@e76453e)) ### [`v16.1.1`](https://github.com/markedjs/marked/releases/tag/v16.1.1) [Compare Source](markedjs/marked@v16.1.0...v16.1.1) ##### Bug Fixes - fix stong and em tokens in angle brackets ([#​3731](markedjs/marked#3731)) ([ad8535c](markedjs/marked@ad8535c)) ### [`v16.1.0`](https://github.com/markedjs/marked/releases/tag/v16.1.0) [Compare Source](markedjs/marked@v16.0.0...v16.1.0) ##### Features - add generic types for parser and renderer output ([#​3722](markedjs/marked#3722)) ([39a0ee3](markedjs/marked@39a0ee3)) ### [`v16.0.0`](https://github.com/markedjs/marked/releases/tag/v16.0.0) [Compare Source](markedjs/marked@v15.0.12...v16.0.0) ##### Bug Fixes - remove cjs build & update min node to 20 ([#​3687](markedjs/marked#3687)) ([0a35d8f](markedjs/marked@0a35d8f)) ##### BREAKING CHANGES - minify ./lib/marked.esm.js and ./lib/marked.umd.js - remove ./marked.min.js use ./lib/marked.umd.js instead - remove ./lib/marked.cjs - update minimum supported node version to 20 to support `require('marked.esm.js')`. see https://nodejs.org/docs/latest-v20.x/api/modules.html#loading-ecmascript-modules-using-require </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (...
# [16.1.0](markedjs/marked@v16.0.0...v16.1.0) (2025-07-17) ### Features * add generic types for parser and renderer output ([#3722](markedjs/marked#3722)) ([8e2bbf6](markedjs/marked@8e2bbf6))
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.