From eee9aea11b327c733ce37453638090c0e9678ee0 Mon Sep 17 00:00:00 2001 From: Lucas Brandstaetter Date: Sat, 16 Nov 2019 02:37:26 +0100 Subject: [PATCH 1/2] Update typings Typings for the convert should include `undefined` or `null`, as they are handled in the convert function. --- index.d.ts | 7 ++++++- package.json | 3 ++- unist-util-is-test.ts | 2 ++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index f05d502..cd2ef07 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 } /** diff --git a/package.json b/package.json index 12fcb8e..ff77971 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,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 3ec9946..85c896e 100644 --- a/unist-util-is-test.ts +++ b/unist-util-is-test.ts @@ -183,3 +183,5 @@ convert({type: 'heading', depth: 2}) convert(isHeading) // $ExpectError convert(isHeading) +convert(null) +convert(undefined) From 53732b333197ee82146bab1fa7f3ded3eacf5abd Mon Sep 17 00:00:00 2001 From: Lucas B Date: Sat, 16 Nov 2019 14:39:53 +0100 Subject: [PATCH 2/2] Fix typings for is function * The test parameter is optional. * Add tests for the is function. --- index.d.ts | 2 +- unist-util-is-test.ts | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/index.d.ts b/index.d.ts index cd2ef07..01e9246 100644 --- a/index.d.ts +++ b/index.d.ts @@ -62,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/unist-util-is-test.ts b/unist-util-is-test.ts index 85c896e..ad4df30 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') @@ -49,8 +51,6 @@ const maybeElement: Element = element is() // $ExpectError is() -// $ExpectError -is(heading) /*=== invalid generic ===*/ // $ExpectError @@ -63,6 +63,11 @@ is<{}>(heading, 'heading') /*=== assignable to boolean ===*/ const wasItAHeading: boolean = is(heading, 'heading') +/*=== type Node test ===*/ +is(heading) +is(heading, null) +is(heading, undefined) + /*=== type string test ===*/ is(heading, 'heading') is(element, 'heading')