typed-regex
typed-regex copied to clipboard
Bug: If part of a capture group is optional then the typing assumes that the whole is optional
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;