typed-regex icon indicating copy to clipboard operation
typed-regex copied to clipboard

Bug: If part of a capture group is optional then the typing assumes that the whole is optional

Open Nokel81 opened this issue 2 years ago • 0 comments

Description:

If a named capture group has some optional grouping itself then the whole group is optional.

Test case:

Current:

const regex = TypedRegEx("^(?<name>((@\\w[-\\w]*\\/)?\\w[-\\w]*))$", "gi");
const captures = regex.captures(...) // { name?: string | undefined } | undefined;

Expected:

const regex = TypedRegEx("^(?<name>((@\\w[-\\w]*\\/)?\\w[-\\w]*))$", "gi");
const captures = regex.captures(...) // { name: string } | undefined;

Nokel81 avatar Mar 29 '22 16:03 Nokel81