Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to correctly compile intrinsic types #31

Merged
merged 3 commits into from
Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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