From 73446d55e1a5749110ba742a5c0d678dce1bc2b6 Mon Sep 17 00:00:00 2001 From: Starrah Date: Mon, 14 Mar 2022 20:15:18 +0800 Subject: [PATCH] Update Typescript Declarations index.d.ts Details: 1. Add @types/picomatch as dependency, and import {PicomatchOptions} from "picomatch". 2. add more function signatures to separate different type of return value: when returnIndex=true, the return value is number, otherwise the return value is boolean. --- index.d.ts | 11 +++++++---- package.json | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/index.d.ts b/index.d.ts index 3ef7eaa..278967c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,3 +1,5 @@ +import {PicomatchOptions} from "picomatch"; + type AnymatchFn = (testString: string) => boolean; type AnymatchPattern = string|RegExp|AnymatchFn; type AnymatchMatcher = AnymatchPattern|AnymatchPattern[] @@ -5,13 +7,14 @@ type AnymatchTester = { (testString: string|any[], returnIndex: true): number; (testString: string|any[]): boolean; } - -type PicomatchOptions = {dot: boolean}; +type AnymatchOptions = {returnIndex?: boolean} & PicomatchOptions declare const anymatch: { (matchers: AnymatchMatcher): AnymatchTester; - (matchers: AnymatchMatcher, testString: null, returnIndex: true | PicomatchOptions): AnymatchTester; - (matchers: AnymatchMatcher, testString: string|any[], returnIndex: true | PicomatchOptions): number; + (matchers: AnymatchMatcher, testString: null, returnIndex: true | AnymatchOptions): AnymatchTester; + (matchers: AnymatchMatcher, testString: string|any[], returnIndex: true): number; + (matchers: AnymatchMatcher, testString: string|any[], options: {returnIndex: true} & PicomatchOptions): number; + (matchers: AnymatchMatcher, testString: string|any[], options: {returnIndex?: false} & PicomatchOptions): boolean; (matchers: AnymatchMatcher, testString: string|any[]): boolean; } diff --git a/package.json b/package.json index f9b5284..fa229c2 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "index.d.ts" ], "dependencies": { + "@types/picomatch": "^2.3.0", "normalize-path": "^3.0.0", "picomatch": "^2.0.4" },