-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
Currently, when parsing regexes with captures, their types are inferred as either string or string | undefined depending on the capture definition.
However, there are many simple use-cases that would benefit from analyzing captures more literally and having stricter typing for their values:
const fruit = typedRegExp('(banana|apple|pear|orange)');
const banana = fruit.exec('banana')![1];
// Currently typed as:
// string
// Could be typed as:
// 'banana' | 'apple' | 'pear' | 'orange'
// But since we know the type of the string, it could be typed as just:
// 'banana' | 'apple' | 'pear' | 'orange' & 'banana' -> just 'banana'
// This is, however, unrealistic for more complex patterns...Metadata
Metadata
Assignees
Labels
No labels