-
Notifications
You must be signed in to change notification settings - Fork 12.8k
[ID] --isolatedDeclarations
disallows const
initialized with a regex literal
#58383
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
--isolatedDeclarations
don't alow const
initialized with a regex literal
--isolatedDeclarations
don't alow const
initialized with a regex literal--isolatedDeclarations
disallows const
initialized with a regex literal
--isolatedDeclarations
disallows const
initialized with a regex literal--isolatedDeclarations
disallows const
initialized with a regex literal
This would require us to hardcode the type of a regex expression, no? Since regexes aren't an intrinsic and aren't valid initializers in dts? I guess it could always just be RegExp, so long as that type name hasn't been reused. It's not like "number" or a literal value where the type name is reserved. |
This seems like the same situation as any other literal type, except that regex literal types don't exist, so we can safely write |
Just hope we never add stricter RegExp types... Does the quick fix at least suggest adding |
#32098 is really close with our recent regex parsing changes in, but I don't think that'd block this, actually. Whenever we start emitting a On the flip side, since I'm pretty sure that once we have more detailed types for the literal like that, they actually probably need widening behaviors like other literal types, so if you do x = /(?<a>a)/
x = /(?<b>b)/ you want |
π Search Terms
β Viability Checklist
β Suggestion
I an unsure if it is a bug or a feature request...
An exported
const
without type annotation and initialized with a regex literal triggers the following errorerror TS9010: Variable must have an explicit type annotation with --isolatedDeclarations.
in isolated declaration mode.If I understand correctly, isolated declaration should allow unannotated
const
initialized with any literal?π Motivating Example
See an example on the playground.
π» Use Cases
This could avoid a trivial type annotation.
The text was updated successfully, but these errors were encountered: