magic-regexp icon indicating copy to clipboard operation
magic-regexp copied to clipboard

`Predefined Input can not be assigned to InputSource` when using with TypeScript < 4.7

Open tim3trick opened this issue 3 years ago • 6 comments

I just installed magic-regexp via yarn add magic-regexp and tried the first example from https://regexp.dev/getting-started/examples

Typescript does not like it though: Argument of type 'Input<"\\d", never>' is not assignable to parameter of type 'InputSource<string, never>'.

The code can also be simplified even more: const regex = createRegExp(oneOrMore(digit));

I have created a codesandbox for showcasing this: https://codesandbox.io/s/gracious-swartz-3sdfcs

tim3trick avatar Aug 23 '22 09:08 tim3trick

Addition: oneOrMore('x') fails with the same when used inside and, i have updated the sandbox: https://codesandbox.io/s/angry-wave-fr0m5s?file=/src/index.ts

Code that fails: createRegExp( oneOrMore('a') .and('.') .and(oneOrMore('b')) )

tim3trick avatar Aug 23 '22 09:08 tim3trick

You can see it working fine in stackblitz (here). It also works fine for me locally.

CleanShot 2022-08-23 at 10 59 54

Are you getting this locally, or just in codesandbox (which seems to be using TS 4.4)? If so, what is your local TypeScript version?

danielroe avatar Aug 23 '22 10:08 danielroe

I get this locally with 4.6.3 as well.

tim3trick avatar Aug 23 '22 11:08 tim3trick

Yes - confirmed. You need features from TS 4.7+; versions below that show this error.

danielroe avatar Aug 23 '22 12:08 danielroe

Excuse the question, but am I supposed to to something with the ticket?

tim3trick avatar Aug 26 '22 10:08 tim3trick

@tim3trick No need to do anything. For now you can use a newer version of TypeScript. I'll keep this open until I've had a chance to see whether it's possible to make the features of this library work with earlier versions of TS or whether I should instead mention it in the README.

danielroe avatar Aug 27 '22 20:08 danielroe