diff --git a/index.d.ts b/index.d.ts index f05d502..01e9246 100644 --- a/index.d.ts +++ b/index.d.ts @@ -37,7 +37,12 @@ declare namespace unistUtilIs { * * @typeParam T type of node that passes test */ - type Test = TestType | TestObject | TestFunction + type Test = + | TestType + | TestObject + | TestFunction + | null + | undefined } /** @@ -57,7 +62,7 @@ declare namespace unistUtilIs { */ declare function unistUtilIs( node: unknown, - test: unistUtilIs.Test | Array>, + test?: unistUtilIs.Test | Array>, index?: number, parent?: Parent, context?: any diff --git a/package.json b/package.json index 87d1eae..1baec51 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,8 @@ "author": "Titus Wormer (https://wooorm.com)", "contributors": [ "Titus Wormer (https://wooorm.com)", - "Christian Murphy " + "Christian Murphy ", + "Lucas Brandstaetter (https://github.com/Roang-zero1)" ], "files": [ "index.js", diff --git a/unist-util-is-test.ts b/unist-util-is-test.ts index b567081..6edd55d 100644 --- a/unist-util-is-test.ts +++ b/unist-util-is-test.ts @@ -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') @@ -47,8 +49,6 @@ const maybeElement: Element = element is() // $ExpectError is() -// $ExpectError -is(heading) /* Incorrect generic. */ // $ExpectError @@ -61,6 +61,11 @@ is>(heading, 'heading') /* Should be assignable to boolean. */ const wasItAHeading: boolean = is(heading, 'heading') +/* Test is optional */ +is(heading) +is(heading, null) +is(heading, undefined) + /* Should support string tests. */ is(heading, 'heading') is(element, 'heading') @@ -190,3 +195,5 @@ convert({type: 'heading', depth: 2}) convert(isHeading) // $ExpectError convert(isHeading) +convert(null) +convert(undefined)