Skip to content

Commit

Permalink
Use @types/nlcst
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Aug 27, 2021
1 parent 7fd4166 commit 97b60d4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
9 changes: 6 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/**
* @typedef {import('unist').Node} Node
* @typedef {import('unist').Parent} Parent
* @typedef {import('unist').Parent} UnistParent
* @typedef {import('nlcst').Root} Root
* @typedef {import('nlcst').Content} Content
* @typedef {Root|Content} Node
* @typedef {Extract<Node, UnistParent>} Parent
*/

import nodeAssert from 'node:assert'
Expand Down Expand Up @@ -92,7 +95,7 @@ function assertParent(node) {
/**
* @param {unknown} node
* @param {Parent} [ancestor]
* @returns {asserts node is Parent}
* @returns {asserts node is Root}
*/
function RootNode(node, ancestor) {
parent(node)
Expand Down
8 changes: 6 additions & 2 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import {expectType, expectNotType} from 'tsd'
import {Node, Parent} from 'unist'
import type {Parent as UnistParent} from 'unist'
import type {Root, Content} from 'nlcst'
import {assert, parent} from './index.js'

type Node = Root | Content
type Parent = Extract<Node, UnistParent>

const emptyNode = {type: 'a'}
const literalNode = {type: 'b', value: 'c'}
const literalNode = {type: 'TextNode', value: 'c'}
const parentNode = {type: 'd', children: [emptyNode, literalNode]}

expectNotType<Node>(emptyNode)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"index.js"
],
"dependencies": {
"@types/nlcst": "^1.0.0",
"@types/unist": "^2.0.0",
"mapz": "^2.0.0",
"unist-util-assert": "^3.0.0",
Expand Down

0 comments on commit 97b60d4

Please sign in to comment.