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
I found multiple issues with .at() when used with tuples. Since tuple is strictly typed array by indexes, I think that the type inference with .at() should be better.
🔎 Search Terms
array
array.at()
at()
tuple
array.at() with tuple
tuple at()
🕗 Version & Regression Information
Version: 4.8.2 (also 4.9.0-dev.20220921)
This is the behavior in every version I tried, and I reviewed the FAQ for entries about arrays and tuples with .at()
consttuple: [string,number]=['1',2]// 1. Shows that "a" can be undefined, but should be a string// 2. Shows that "a" can be number, but should be stringconsta=tuple.at(0)constb=tuple[0]// this is correct// 3. Shows type error with bracket notation but no type error with .at()constd=tuple.at(3)constc=tuple[3]// shows type error which is correct
🙁 Actual behavior
When I use .at() with tuple, it wrongly infers type.
It shows string | number | undefined when used with an existing index.
It doesn't show a type error when used with an index that doesn't exist
🙂 Expected behavior
I would expect, that it works the same as with bracket notation [] when used with a tuple. Because it knows what type is at what index. Also if that index exists in that tuple.
The text was updated successfully, but these errors were encountered:
Bug Report
I found multiple issues with
.at()
when used with tuples. Since tuple is strictly typed array by indexes, I think that the type inference with.at()
should be better.🔎 Search Terms
🕗 Version & Regression Information
Version:
4.8.2
(also4.9.0-dev.20220921
).at()
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
When I use
.at()
with tuple, it wrongly infers type.string | number | undefined
when used with an existing index.🙂 Expected behavior
I would expect, that it works the same as with bracket notation
[]
when used with a tuple. Because it knows what type is at what index. Also if that index exists in that tuple.The text was updated successfully, but these errors were encountered: