Skip to content

Commit

Permalink
Fix to correctly compile intrinsic types
Browse files Browse the repository at this point in the history
Reviewed-by: Remco Haszing <remcohaszing@gmail.com>
Reviewed-by: Titus Wormer <tituswormer@gmail.com>

Related to GH-31.
  • Loading branch information
ChristianMurphy committed Aug 26, 2021
1 parent 28c6279 commit dac20e2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
coverage/
node_modules/
.DS_Store
lib/index.d.ts
lib/*.d.ts
test.d.ts
*.log
yarn.lock
43 changes: 43 additions & 0 deletions lib/complex-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import type {ComponentType} from 'react'
import type {Element} from 'hast'

interface WithNode {
node: Element
}

export interface ComponentsWithNodeOptions {
/**
* Expose hast elements as a `node` field in components
*/
passNode: true
/**
* Override default elements (such as `<a>`, `<p>`, etcetera) by passing an
* object mapping tag names to components.
*/
components?: Partial<
{
[TagName in keyof JSX.IntrinsicElements]:
| keyof JSX.IntrinsicElements
| ComponentType<WithNode & JSX.IntrinsicElements[TagName]>
}
>
}

export interface ComponentsWithoutNodeOptions {
/**
* Expose hast elements as a `node` field in components.
*/
passNode?: false | undefined

/**
* Override default elements (such as `<a>`, `<p>`, etcetera) by passing an
* object mapping tag names to components.
*/
components?: Partial<
{
[TagName in keyof JSX.IntrinsicElements]:
| keyof JSX.IntrinsicElements
| ComponentType<JSX.IntrinsicElements[TagName]>
}
>
}
20 changes: 1 addition & 19 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,7 @@
* @property {string|undefined} [prefix='h-']
* React key prefix
*
* @typedef WithNode
* @property {Element} node
* Current hast element.
*
* @typedef ComponentsWithNodeOptions
* @property {true} passNode
* Expose hast elements as a `node` field in components.
* @property {Partial<{[TagName in keyof JSX.IntrinsicElements]: string|((props: WithNode & JSX.IntrinsicElements[TagName]) => ReactNode)}>} [components]
* Override default elements (such as `<a>`, `<p>`, etcetera) by passing an
* object mapping tag names to components.
*
* @typedef ComponentsWithoutNodeOptions
* @property {false|undefined} [passNode]
* Expose hast elements as a `node` field in components.
* @property {Partial<{[TagName in keyof JSX.IntrinsicElements]: string|((props: JSX.IntrinsicElements[TagName]) => ReactNode)}>} [components]
* Override default elements (such as `<a>`, `<p>`, etcetera) by passing an
* object mapping tag names to components.
*
* @typedef {SharedOptions & (ComponentsWithNodeOptions|ComponentsWithoutNodeOptions)} Options
* @typedef {SharedOptions & (import("./complex-types").ComponentsWithNodeOptions|import("./complex-types").ComponentsWithoutNodeOptions)} Options
*/

import {toH} from 'hast-to-hyperscript'
Expand Down

0 comments on commit dac20e2

Please sign in to comment.