You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems like I can resolve this by changing the extends type to be string[] | [string] without any changes in or loss of functionality.
It's very possible that this is The Correct Type I should be using for typing this the most accurately, but will leave this issue open for now as it still strikes me as a little odd that accessing the second item changes the inferred type of the first item, given it's redundant in JS (which is what got me here: eslint rules telling me it's not needed).
Somewhat surprisingly - this one infers ["1"] whereas the one that you proposed infers [string].
It's definitely weird to me that adding a pattern for the second item in this destructuring makes it infer a tuple. But then... I'm not sure what the bug is. Should the tuple be inferred for const [[x]] = or should the tuple not be inferred for const [[x], []] =? 😅
Bug Report
When using
noUncheckedIndexedAccess
, the type inferred by my code is affected by whether I access the second item in a tuple or not.🔎 Search Terms
tuple, undefined, type, omit, noUncheckedIndexedAccess, error, index, array, infer, nested
🕗 Version & Regression Information
noUncheckedIndexedAccess
--noUncheckedIndexedAccess
didn't exist before those versions⏯ Playground Link
Playground link with relevant code
💻 Code
It seems that the inferred type for
fn
is:Since the first item is an array rather than a tuple, items in that array have type
string | undefined
.If I change the assignment to be:
It gets inferred as:
Since the first item is a tuple rather than an array, items in that tuple have type
string
.🙁 Actual behavior
x
has typestring | undefined
🙂 Expected behavior
x
has typestring
.The text was updated successfully, but these errors were encountered: