Skip to content

Commit b151a90

Browse files
authored
Fix types for React 19
Closes GH-879. Reviewed-by: Christian Murphy <christian.murphy.42@gmail.com> Reviewed-by: Titus Wormer <tituswormer@gmail.com>
1 parent 27d3949 commit b151a90

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
* @typedef {import('hast-util-to-jsx-runtime').ExtraProps} ExtraProps
32
* @typedef {import('./lib/index.js').AllowElement} AllowElement
43
* @typedef {import('./lib/index.js').Components} Components
4+
* @typedef {import('./lib/index.js').ExtraProps} ExtraProps
55
* @typedef {import('./lib/index.js').Options} Options
66
* @typedef {import('./lib/index.js').UrlTransform} UrlTransform
77
*/

lib/index.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/**
22
* @import {Element, ElementContent, Nodes, Parents, Root} from 'hast'
3-
* @import {Components as JsxRuntimeComponents} from 'hast-util-to-jsx-runtime'
4-
* @import {ReactElement} from 'react'
3+
* @import {ComponentProps, ElementType, ReactElement} from 'react'
54
* @import {Options as RemarkRehypeOptions} from 'remark-rehype'
65
* @import {BuildVisitor} from 'unist-util-visit'
76
* @import {PluggableList} from 'unified'
@@ -21,7 +20,16 @@
2120
*/
2221

2322
/**
24-
* @typedef {Partial<JsxRuntimeComponents>} Components
23+
* @typedef ExtraProps
24+
* Extra fields we pass.
25+
* @property {Element | undefined} [node]
26+
* passed when `passNode` is on.
27+
*/
28+
29+
/**
30+
* @typedef {{
31+
* [Key in Extract<ElementType, string>]?: ElementType<ComponentProps<Key> & ExtraProps>
32+
* }} Components
2533
* Map tag names to components.
2634
*/
2735

@@ -225,6 +233,9 @@ export function Markdown(options) {
225233

226234
return toJsxRuntime(hastTree, {
227235
Fragment,
236+
// @ts-expect-error
237+
// React components are allowed to return numbers,
238+
// but not according to the types in hast-util-to-jsx-runtime
228239
components,
229240
ignoreInvalidStyle: true,
230241
jsx,

0 commit comments

Comments
 (0)