unjs / magic-regexp

A compiled-away, type-safe, readable RegExp alternative

Home Page:https://regexp.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

tim3trick opened this issue · 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

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')) )

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?

I get this locally with 4.6.3 as well.

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

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

@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.