Skip to content

Commit

Permalink
Refactor to use @imports
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Sep 19, 2024
1 parent c62d719 commit e4576c0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
10 changes: 5 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
/// <reference types="mdast-util-to-hast" />

/**
* @typedef {import('hast').Root} HastRoot
* @typedef {import('mdast').Root} MdastRoot
* @typedef {import('mdast-util-to-hast').Options} ToHastOptions
* @typedef {import('unified').Processor} Processor
* @typedef {import('vfile').VFile} VFile
* @import {Root as HastRoot} from 'hast'
* @import {Root as MdastRoot} from 'mdast'
* @import {Options as ToHastOptions} from 'mdast-util-to-hast'
* @import {Processor} from 'unified'
* @import {VFile} from 'vfile'
*/

/**
Expand Down
13 changes: 7 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -575,17 +575,18 @@ The types of `mdast-util-to-hast` can be referenced to register data fields
with `@types/mdast` and `Raw` nodes with `@types/hast`.

```js
// Include `data` fields in mdast and `raw` nodes in hast.
/// <reference types="mdast-util-to-hast" />
/**
* @import {Root as HastRoot} from 'hast'
* @import {Root as MdastRoot} from 'mdast'
* @import {} from 'mdast-util-to-hast'
*/

import {visit} from 'unist-util-visit'

/** @type {import('mdast').Root} */
const mdastNode = {/**/}
const mdastNode = /** @type {MdastRoot} */ ({/**/})
console.log(mdastNode.data?.hName) // Typed as `string | undefined`.

/** @type {import('hast').Root} */
const hastNode = {/**/}
const hastNode = /** @type {HastRoot} */ ({/**/})

visit(hastNode, function (node) {
// `node` can now be `raw`.
Expand Down

0 comments on commit e4576c0

Please sign in to comment.