codpro2005/ts-regexp

Allow RegExp literal argument

Opened this issue · 1 comments

Like this:

const res = typedRegExp(/myPattern/);

This is a current TypeScript limitation as RegExp literals can't be const asserted, assumingly because they become class instances which by design are mutable:

const pattern = /myPattern/.source
//   ?^ string

Considering that RegExp.prototype.compile is deprecated now and the only way to mutate the source and flags properties, given that they are marked as readonly, potentially consider making a TypeScript issue to allow this as an exception.

Edit: An issue suggesting this for RegExp literal flags already exists here.