syntax-tree / unist-util-is

utility to check if a node passes a test
https://unifiedjs.com
MIT License
38 stars 8 forks source link

Add JSDoc based types #18

Closed wooorm closed 3 years ago

wooorm commented 3 years ago

Initial checklist

Description of changes

This changes from manual .d.ts files to JSDoc generated .d.ts files.

Notably, to review, here’s what the generated types look like: ```ts /** * @typedef {import('unist').Node} Node * @typedef {import('unist').Parent} Parent * * @typedef {string} Type * @typedef {Object} Props */ /** * Check if a node passes a test * * @callback TestFunctionAnything * @param {Node} node * @param {number} [index] * @param {Parent} [parent] * @returns {boolean|void} */ /** * Check if a node passes a certain node test * * @template {Node} X * @callback TestFunctionPredicate * @param {Node} node * @param {number} [index] * @param {Parent} [parent] * @returns {node is X} */ /** * @callback AssertAnything * @param {unknown} [node] * @param {number} [index] * @param {Parent} [parent] * @returns {boolean} */ /** * Check if a node passes a certain node test * * @template {Node} Y * @callback AssertPredicate * @param {unknown} [node] * @param {number} [index] * @param {Parent} [parent] * @returns {node is Y} */ /** * Check if a node passes a test. * When a `parent` node is known the `index` of node should also be given. * * @type {( * ((node: unknown, test?: null|undefined, index?: number, parent?: Parent, context?: unknown) => node is Node) & * ((node: unknown, test: T['type']|Partial|TestFunctionPredicate|Array.|TestFunctionPredicate>, index?: number, parent?: Parent, context?: unknown) => node is T) & * ((node?: unknown, test?: null|undefined|Type|Props|TestFunctionAnything|Array., index?: number, parent?: Parent, context?: unknown) => boolean) * )} */ export var is: (( node: unknown, test?: null | undefined, index?: number, parent?: Parent, context?: unknown ) => node is import('unist').Node) & (( node: unknown, test: | T_1['type'] | Partial | TestFunctionPredicate | Array | TestFunctionPredicate>, index?: number, parent?: Parent, context?: unknown ) => node is T_1) & (( node?: unknown, test?: | null | undefined | Type | Props | TestFunctionAnything | Array, index?: number, parent?: Parent, context?: unknown ) => boolean) /** * @type {( * ((test?: null|undefined) => AssertPredicate) & * ((test: T['type']|Partial|TestFunctionPredicate) => AssertPredicate) & * ((test?: null|undefined|Type|Props|TestFunctionAnything|Array.) => AssertAnything) * )} */ export var convert: (( test?: null | undefined ) => AssertPredicate) & (( test: T_1['type'] | Partial | TestFunctionPredicate ) => AssertPredicate) & (( test?: | null | undefined | Type | Props | TestFunctionAnything | Array ) => AssertAnything) export type Node = import('unist').Node export type Parent = import('unist').Parent export type Type = string export type Props = Record /** * Check if a node passes a test */ export type TestFunctionAnything = ( node: Node, index?: number, parent?: Parent ) => boolean | void /** * Check if a node passes a certain node test */ export type TestFunctionPredicate = ( node: Node, index?: number, parent?: Parent ) => node is X export type AssertAnything = ( node?: unknown, index?: number, parent?: Parent ) => boolean /** * Check if a node passes a certain node test */ export type AssertPredicate = ( node?: unknown, index?: number, parent?: Parent ) => node is Y ```
github-actions[bot] commented 3 years ago

Hi! This is accepted and can go somewhere!

Team: please review this PR and use the area/* (to describe the scope of the change), platform/* (if this is related to a specific one), and semver/* and type/* labels to annotate this.

github-actions[bot] commented 3 years ago

Hi! This is accepted and can go somewhere!

Team: please review this PR and use the area/* (to describe the scope of the change), platform/* (if this is related to a specific one), and semver/* and type/* labels to annotate this.