Skip to content

Update typings for convert #11

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

Merged
merged 3 commits into from
Mar 7, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 7 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ declare namespace unistUtilIs {
*
* @typeParam T type of node that passes test
*/
type Test<T extends Node> = TestType<T> | TestObject<T> | TestFunction<T>
type Test<T extends Node> =
| TestType<T>
| TestObject<T>
| TestFunction<T>
| null
| undefined
}

/**
Expand All @@ -57,7 +62,7 @@ declare namespace unistUtilIs {
*/
declare function unistUtilIs<T extends Node>(
node: unknown,
test: unistUtilIs.Test<T> | Array<unistUtilIs.Test<any>>,
test?: unistUtilIs.Test<T> | Array<unistUtilIs.Test<any>>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be test?: unistUtilIs.Test<T> | Array<unistUtilIs.Test<any>> | null. And don't forget to fix convert function too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed only if null and undefined are removed from Test correct?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

index?: number,
parent?: Parent,
context?: any
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"author": "Titus Wormer <[email protected]> (https://wooorm.com)",
"contributors": [
"Titus Wormer <[email protected]> (https://wooorm.com)",
"Christian Murphy <[email protected]>"
"Christian Murphy <[email protected]>",
"Lucas Brandstaetter <[email protected]> (https://github.com/Roang-zero1)"
],
"files": [
"index.js",
Expand Down
11 changes: 9 additions & 2 deletions unist-util-is-test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {Node, Parent} from 'unist'

import {Heading} from 'mdast'

import unified = require('unified')
import is = require('unist-util-is')
import convert = require('unist-util-is/convert')
Expand Down Expand Up @@ -49,8 +51,6 @@ const maybeElement: Element = element
is()
// $ExpectError
is<Node>()
// $ExpectError
is<Node>(heading)

/*=== invalid generic ===*/
// $ExpectError
Expand All @@ -63,6 +63,11 @@ is<{}>(heading, 'heading')
/*=== assignable to boolean ===*/
const wasItAHeading: boolean = is<Heading>(heading, 'heading')

/*=== type Node test ===*/
is<Node>(heading)
is<Node>(heading, null)
is<Node>(heading, undefined)

/*=== type string test ===*/
is<Heading>(heading, 'heading')
is<Heading>(element, 'heading')
Expand Down Expand Up @@ -183,3 +188,5 @@ convert<Element>({type: 'heading', depth: 2})
convert<Heading>(isHeading)
// $ExpectError
convert<Element>(isHeading)
convert<Node>(null)
convert<Node>(undefined)