anymatch
anymatch copied to clipboard
Can't use Picomatch options with returnIndex in TypeScript
I was trying to do something like this:
const processorIndex = anymatch(this.processorGlobs, relativePath, {
dot: true,
returnIndex: true
});
But I get the following error:
error TS2345: Argument of type '{ dot: true; returnIndex: boolean; }' is not assignable to parameter of type 'true | PicomatchOptions'.
Object literal may only specify known properties, and 'returnIndex' does not exist in type 'PicomatchOptions'.
26 returnIndex: true
~~~~~~~~~~~~~~~~~
Found 1 error.
I think the typings should be changed to allow this, e.g.:
-(matchers: AnymatchMatcher, testString: string|any[], returnIndex: true | PicomatchOptions): number;
+(matchers: AnymatchMatcher, testString: string|any[], returnIndex: true | PicomatchOptions & { returnIndex?: boolean }): number;
The docs is misleading, it indicates we can use PicomatchOptions, but the type is hardcoded to either be returnIndex:true or {dot:boolean}
https://github.com/micromatch/anymatch/blob/master/index.d.ts#L9