Skip to content

Commit 656a4fa

Browse files
authoredJan 2, 2022
Fix ref in types
Closes GH-668. Reviewed-by: Remco Haszing <remcohaszing@gmail.com> Reviewed-by: Titus Wormer <tituswormer@gmail.com>
1 parent 9a25ef8 commit 656a4fa

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed
 

‎lib/ast-to-react.js

+12-7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
* @typedef {import('react').ComponentType<T>} ComponentType<T>
44
*/
55

6+
/**
7+
* @template T
8+
* @typedef {import('react').ComponentPropsWithoutRef<T>} ComponentPropsWithoutRef<T>
9+
*/
10+
611
/**
712
* @typedef {import('react').ReactNode} ReactNode
813
* @typedef {import('unist').Position} Position
@@ -49,13 +54,13 @@
4954
*
5055
* To do: is `data-sourcepos` typeable?
5156
*
52-
* @typedef {JSX.IntrinsicElements['code'] & ReactMarkdownProps & {inline?: boolean}} CodeProps
53-
* @typedef {JSX.IntrinsicElements['h1'] & ReactMarkdownProps & {level: number}} HeadingProps
54-
* @typedef {JSX.IntrinsicElements['li'] & ReactMarkdownProps & {checked: boolean|null, index: number, ordered: boolean}} LiProps
55-
* @typedef {JSX.IntrinsicElements['ol'] & ReactMarkdownProps & {depth: number, ordered: true}} OrderedListProps
56-
* @typedef {JSX.IntrinsicElements['table'] & ReactMarkdownProps & {style?: Record<string, unknown>, isHeader: boolean}} TableCellProps
57-
* @typedef {JSX.IntrinsicElements['tr'] & ReactMarkdownProps & {isHeader: boolean}} TableRowProps
58-
* @typedef {JSX.IntrinsicElements['ul'] & ReactMarkdownProps & {depth: number, ordered: false}} UnorderedListProps
57+
* @typedef {ComponentPropsWithoutRef<'code'> & ReactMarkdownProps & {inline?: boolean}} CodeProps
58+
* @typedef {ComponentPropsWithoutRef<'h1'> & ReactMarkdownProps & {level: number}} HeadingProps
59+
* @typedef {ComponentPropsWithoutRef<'li'> & ReactMarkdownProps & {checked: boolean|null, index: number, ordered: boolean}} LiProps
60+
* @typedef {ComponentPropsWithoutRef<'ol'> & ReactMarkdownProps & {depth: number, ordered: true}} OrderedListProps
61+
* @typedef {ComponentPropsWithoutRef<'table'> & ReactMarkdownProps & {style?: Record<string, unknown>, isHeader: boolean}} TableCellProps
62+
* @typedef {ComponentPropsWithoutRef<'tr'> & ReactMarkdownProps & {isHeader: boolean}} TableRowProps
63+
* @typedef {ComponentPropsWithoutRef<'ul'> & ReactMarkdownProps & {depth: number, ordered: false}} UnorderedListProps
5964
*
6065
* @typedef {ComponentType<CodeProps>} CodeComponent
6166
* @typedef {ComponentType<HeadingProps>} HeadingComponent

‎lib/complex-types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type {ReactNode, ComponentType} from 'react'
1+
import type {ReactNode, ComponentType, ComponentPropsWithoutRef} from 'react'
22
import type {Position} from 'unist'
33
import type {Element} from 'hast'
44

@@ -24,5 +24,5 @@ export interface ReactMarkdownProps {
2424
export type NormalComponents = {
2525
[TagName in keyof JSX.IntrinsicElements]:
2626
| keyof JSX.IntrinsicElements
27-
| ComponentType<JSX.IntrinsicElements[TagName] & ReactMarkdownProps>
27+
| ComponentType<ComponentPropsWithoutRef<TagName> & ReactMarkdownProps>
2828
}

‎test/test.jsx

-1
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,6 @@ test('should be able to render components with forwardRef in HOC', () => {
11611161
const wrapped = (props) => <a {...props} />
11621162

11631163
const actual = asHtml(
1164-
// @ts-expect-error: something up with types for refs.
11651164
<Markdown components={{a: wrapper(wrapped)}}>
11661165
[Link](https://example.com/)
11671166
</Markdown>

0 commit comments

Comments
 (0)
Please sign in to comment.