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
{{ message }}
Repository navigation
Rest declarations in destructured arrays receiving incorrect types from tuples declaring the types in the destructured array #16700
Expected behavior:
When destructuring the method parameter (which can be an array of potentially anything after middleware has had its say, but I know exactly what it will be in this case) I've gathered the remaining array values (which I know to be strings) into roleNames and declared the type of the variables in the destructured array via the tuple [ResourceLoader, string, string[]].
I expect roleNames to take on the declared type from the tuple as res and commandName have correctly done.
Actual behavior:
When hovering over the roleNames declaration I get the following:
varroleNames: (string|ResourceLoader|string[])[]
Apologies for the convoluted title. Couldn't think of a less verbose description.
The type [ResourceLoader, string, string[]] probably isn't what you had in mind. What you really want is an open-ended tuple where all of the trailing elements are known to be strings.
I've actually recently re-engineered the code in question because it allowed me to merge the functionality of two separate things into one, so I'm actually just receiving a string where ...roleNames used to exist and parsing potentially multiple roles within the function body, but I am still interested in a resolution to this problem.
I'm not entirely sure what you mean by open-ended tuple. Given what you've linked is a proposal, is this something that is possible in current TS?
Activity
DanielRosenwasser commentedon Mar 22, 2018
The type
[ResourceLoader, string, string[]]probably isn't what you had in mind. What you really want is an open-ended tuple where all of the trailing elements are known to bestrings.Generally related is #5453.
zajrik commentedon Mar 23, 2018
I've actually recently re-engineered the code in question because it allowed me to merge the functionality of two separate things into one, so I'm actually just receiving a string where
...roleNamesused to exist and parsing potentially multiple roles within the function body, but I am still interested in a resolution to this problem.I'm not entirely sure what you mean by open-ended tuple. Given what you've linked is a proposal, is this something that is possible in current TS?
ahejlsberg commentedon Jun 26, 2018
Now implemented in #24897.
zajrik commentedon Jul 22, 2018
I somehow missed seeing this get closed, but I saw this change in the 3.0 RC and thought "Hey, that was my issue!"
Glad to see this resolved. Cheers 🎉