suggestion: correct types of flag booleans for RegExp literals #21290
Labels
Suggestion
An idea for TypeScript
Too Complex
An issue which adding support for may be too complex for the value it adds
TypeScript Version: 2.7.0-dev.20180118
Search Terms
Code
Expected behavior:
the type
Sticky
should be compatible with any regex that has they
flag, and incompatible with those that don'tthe type of
/a/y.sticky
should betrue
and/a/y.global
should befalse
Actual behavior:
typescript doesn't seem to care about the flags and always treats
sticky
and other ones asboolean
even when the flags could be read from the regex literalif you have a function that only works with sticky/global/other weird regexps, you'll have to check the flag yourself with
pattern.sticky
orpattern.flags.includes("y")
the properties are all read-only so the feature shouldn't be unsafe to have
tl;dr:
the flag booleans like
RegExp.prototype.sticky
should be set to the right boolean literal types when their values can be read from the regular expression literal (which is always)as an extra, there are also the two strings
RegExp.prototype.flags
andRegExp.prototype.source
that could be read from the literal (andRegExp
constructor could also set them)flags
string is sorted alphabeticallyPlayground Link:
https://www.typescriptlang.org/play/
Related Issues:
couldn't find any
The text was updated successfully, but these errors were encountered: