-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
String.prototype.split()
with a regex containing a capturing group can return an array of string | undefined
.
#60941
Comments
You need to enable Essentially a duplicate of #52299 and others. |
Not really, it is a different issue.... I searched these before. This should thrown a type error.
|
|
Yeah, this is a different issue. There's a type safety hazard here for sure, given that the resulting array literally contains |
If #32098 was implemented, that would lead towards a more precise solution here: The Seems like a lot of work though. |
The last time I proposed something similar (and arguably far more common): #49228, past wisdom said "not worth the breakage" 🤷♂️ You not only have to using split with a capturing regex, but the capturing group also has to be optional, and I've repeatedly received the impression that TypeScript doesn't want to do anything about optional capturing groups. |
⚙ Compilation target
any
⚙ Library
esnext, dom
Missing / Incorrect Definition
Using split with a negative lookahead and a capturing group can return undefined. See the attached screenshot. When iterating over the array, we lose type safety and encounter runtime errors.
Sample Code
Documentation Link
No response
The text was updated successfully, but these errors were encountered: