Skip to content

Commit 05cd307

Browse files
committed
Fix types to use @types/hast
1 parent aea2d82 commit 05cd307

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

index.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
/**
2-
* @typedef {import('unist').Node} UnistNode
3-
* @typedef {import('hast').Element} HastElement
4-
* @typedef {import('unist-util-visit').Visitor<HastElement>} VisitElement
2+
* @typedef {Root['children'][number]|Root} Node
3+
* @typedef {import('hast').Root} Root
4+
* @typedef {import('hast').Element} Element
5+
* @typedef {import('unist-util-visit').Visitor<Element>} VisitElement
56
*/
67

78
import {headingRank} from 'hast-util-heading-rank'
89
import {visit} from 'unist-util-visit'
910

1011
/**
11-
* @template {UnistNode} T
12+
* @template {Node} T
1213
* @param {T} tree
1314
* @param {number} shift
1415
* @returns {T}
@@ -23,17 +24,19 @@ export function shiftHeading(tree, shift) {
2324
throw new Error('Expected a non-null finite integer, not `' + shift + '`')
2425
}
2526

26-
visit(tree, 'element', visitor)
27+
visit(
28+
tree,
29+
'element',
30+
/** @type {VisitElement} */
31+
(node) => {
32+
let rank = headingRank(node)
2733

28-
return tree
29-
30-
/** @type {VisitElement} */
31-
function visitor(node) {
32-
let rank = headingRank(node)
33-
34-
if (rank) {
35-
rank += shift
36-
node.tagName = 'h' + (rank > 6 ? 6 : rank < 1 ? 1 : rank)
34+
if (rank) {
35+
rank += shift
36+
node.tagName = 'h' + (rank > 6 ? 6 : rank < 1 ? 1 : rank)
37+
}
3738
}
38-
}
39+
)
40+
41+
return tree
3942
}

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
],
3838
"dependencies": {
3939
"@types/hast": "^2.0.0",
40-
"@types/unist": "^2.0.0",
4140
"hast-util-heading-rank": "^2.0.0",
4241
"unist-util-visit": "^3.0.0"
4342
},

0 commit comments

Comments
 (0)