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

[QUESTION] How to create typed function with RegExp or MagicRegExp input? (TypeScript)

kravetsone opened this issue Β· comments

πŸ“š Is your documentation request related to a problem?

How to create typed function with RegExp or MagicRegExp input?

I write something like

function getMatchedResult<R extends MagicRegExp<any, any, any, any> | RegExp>(regexp: R, str: string) {
	return str.match(regexp);
}

it doesn't matter Magic Regexp or just Regexp you place the function ReturnType is RegExpMatchArray | null

And is it possible not to use magic regexp as a dependency but to support it? (for example maybe implement compability types)

I am the maintainer of the Telegram Bot API framework - GramIO
And if i add support magic-regexp it would be amazing

image

I need to allow magic (with type-safety) and not regexp

πŸ” Where should you find it?

No response

ℹ️ Additional context

No response