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
RegExpMatchArray
index 0 incorrectly possibly undefined
when noUncheckedIndexedAccess
is enabled
#42296
Comments
I tried to fix this by adding (''.match(/ /) || []).map(s => s.toLowerCase()); We'd need a fix that didn't create new other problems, IMO |
@RyanCavanaugh sorry I don't understand the problem with adding |
@utkarshkukreti from what i understand the compiler fails to infer the type since the type of the value on the right ( |
@DetachHead thanks, I get it now. I hope someone figures out a solution, |
is there a solution for this? or maybe it's the intended behavior? |
Testing the examples from @RyanCavanaugh and @DetachHead in TypeScript 4.3.5 and above, both seem to work now: I'm not sure if it would still be appropriate to add |
RegExpMatchArray
index 0 incorrectly possibly undefined
when noUncheckedIndexedAccess
is enabled
Bug Report
π Search Terms
RegExpMatchArray noUncheckedIndexedAccess
π Version & Regression Information
4.2.0-dev.20210112
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
index 0 is of type
string|undefined
π Expected behavior
index 0 should be of type
string
, sinceRegExpMatchArray
will always have at least one value in it as when no matches are found, it returnsnull
instead. see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match#return_valuetherefore we can be confident that if a
RegExpMatchArray
is returned, it will always have alength
of at least 1should be something like this:
The text was updated successfully, but these errors were encountered: