anymatch icon indicating copy to clipboard operation
anymatch copied to clipboard

Can't use Picomatch options with returnIndex in TypeScript

Open themaxdavitt opened this issue 4 years ago • 1 comments

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;

themaxdavitt avatar Apr 30 '21 19:04 themaxdavitt

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

paul-vd avatar Apr 18 '24 14:04 paul-vd