Skip to content

Commit

Permalink
types: remove ref from html attributes reflected from instrinsic elem…
Browse files Browse the repository at this point in the history
…ents

related to gh-666
  • Loading branch information
ChristianMurphy committed Dec 31, 2021
1 parent 9a25ef8 commit 9800c41
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
19 changes: 12 additions & 7 deletions lib/ast-to-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
* @typedef {import('react').ComponentType<T>} ComponentType<T>
*/

/**
* @template T
* @typedef {import('react').ComponentPropsWithoutRef<T>} ComponentPropsWithoutRef<T>
*/

/**
* @typedef {import('react').ReactNode} ReactNode
* @typedef {import('unist').Position} Position
Expand Down Expand Up @@ -49,13 +54,13 @@
*
* To do: is `data-sourcepos` typeable?
*
* @typedef {JSX.IntrinsicElements['code'] & ReactMarkdownProps & {inline?: boolean}} CodeProps
* @typedef {JSX.IntrinsicElements['h1'] & ReactMarkdownProps & {level: number}} HeadingProps
* @typedef {JSX.IntrinsicElements['li'] & ReactMarkdownProps & {checked: boolean|null, index: number, ordered: boolean}} LiProps
* @typedef {JSX.IntrinsicElements['ol'] & ReactMarkdownProps & {depth: number, ordered: true}} OrderedListProps
* @typedef {JSX.IntrinsicElements['table'] & ReactMarkdownProps & {style?: Record<string, unknown>, isHeader: boolean}} TableCellProps
* @typedef {JSX.IntrinsicElements['tr'] & ReactMarkdownProps & {isHeader: boolean}} TableRowProps
* @typedef {JSX.IntrinsicElements['ul'] & ReactMarkdownProps & {depth: number, ordered: false}} UnorderedListProps
* @typedef {ComponentPropsWithoutRef<'code'> & ReactMarkdownProps & {inline?: boolean}} CodeProps
* @typedef {ComponentPropsWithoutRef<'h1'> & ReactMarkdownProps & {level: number}} HeadingProps
* @typedef {ComponentPropsWithoutRef<'li'> & ReactMarkdownProps & {checked: boolean|null, index: number, ordered: boolean}} LiProps
* @typedef {ComponentPropsWithoutRef<'ol'> & ReactMarkdownProps & {depth: number, ordered: true}} OrderedListProps
* @typedef {ComponentPropsWithoutRef<'table'> & ReactMarkdownProps & {style?: Record<string, unknown>, isHeader: boolean}} TableCellProps
* @typedef {ComponentPropsWithoutRef<'tr'> & ReactMarkdownProps & {isHeader: boolean}} TableRowProps
* @typedef {ComponentPropsWithoutRef<'ul'> & ReactMarkdownProps & {depth: number, ordered: false}} UnorderedListProps
*
* @typedef {ComponentType<CodeProps>} CodeComponent
* @typedef {ComponentType<HeadingProps>} HeadingComponent
Expand Down
4 changes: 2 additions & 2 deletions lib/complex-types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {ReactNode, ComponentType} from 'react'
import type {ReactNode, ComponentType, ComponentPropsWithoutRef} from 'react'
import type {Position} from 'unist'
import type {Element} from 'hast'

Expand All @@ -24,5 +24,5 @@ export interface ReactMarkdownProps {
export type NormalComponents = {
[TagName in keyof JSX.IntrinsicElements]:
| keyof JSX.IntrinsicElements
| ComponentType<JSX.IntrinsicElements[TagName] & ReactMarkdownProps>
| ComponentType<ComponentPropsWithoutRef<TagName> & ReactMarkdownProps>
}
1 change: 0 additions & 1 deletion test/test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,6 @@ test('should be able to render components with forwardRef in HOC', () => {
const wrapped = (props) => <a {...props} />

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

0 comments on commit 9800c41

Please sign in to comment.