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
Long tuples lose appropriate type information #11924
Limit is seemingly even lower in 1.8.9, with type information loss after the tuple is 6 or more elements wide.
Code
// A *self-contained* demonstration of the problem follows...Promise.all([Promise.resolve(1),Promise.resolve(''),Promise.resolve(newDate()),]).then(results=>{let[a,// Numberb,// Stringc,// Date - Everything is ok!]=results;});Promise.all([Promise.resolve(1),Promise.resolve(''),Promise.resolve(newDate()),Promise.resolve({}),Promise.resolve({hi: 'hello'}),Promise.resolve([]),Promise.resolve(nullasstring),Promise.resolve(1),Promise.resolve(''),Promise.resolve(newDate()),Promise.resolve({}),// Length == 11]).then(results=>{let[a,// Everything is {} now?b,c,d,e,f,g,h,i,j,k,// << -- Error!// "Tuple with length 10 cannot be assigned to tuple with length 11"?]=results;});
Ryan Cavanaugh (@RyanCavanaugh) the fact that you can't meaningfully distinguish between them is a problem no matter what though:
// This type checks even though it shouldn'tfunctionbad(foo: [number,string]): [number,string]{returnfoo.sort()}
It seems that while representing tuples as arrays at runtime is fine and dandy, perhaps at compile time they should be kept distinguished, i.e. [number, string] and (number|string)[] should be considered mutually incompatible types.
I know, I'm saying that tuples should not be considered subtypes of Array, in which case the sort method wouldn't be available on them. It makes no sense to sort a tuple.
Reacted by Jakub Korzeniowski, Flavien Volken, Aluan Haddad and Bo Lingen
describe('promiseObject',()=>{it('should await an object of promises',async()=>{const{a, b}=awaitpromiseObject({a: Promise.resolve(1),b: Promise.resolve('b')});expect(a).to.equal(1);expect(b).to.equal('b');});});
Activity
blakeembrey commentedon Oct 28, 2016
This comes from the promise definition, the maximum overload of tuples in the definition is 10. See https://github.com/Microsoft/TypeScript/blob/master/lib/lib.es6.d.ts#L5289.
jocull commentedon Oct 28, 2016
Tuple types are apparently not inferred anywhere else. Why is that since the types are definitely known in cases such as this?
Code on the playground.
RyanCavanaugh commentedon Oct 28, 2016
Because we can't meaningfully distinguish these two cases:
RyanCavanaugh commentedon Oct 28, 2016
It's also not at all apparent that the fact that you wrote
implies that you want it to be illegal to write
jocull commentedon Nov 2, 2016
You guys can close this issue if you want - no need to leave it cluttering more relevant issues.
I appreciate you taking the time to answer my questions. Everyone has clearly thought through the issues and edge cases here!
pelotom commentedon Dec 23, 2016
Ryan Cavanaugh (@RyanCavanaugh) the fact that you can't meaningfully distinguish between them is a problem no matter what though:
It seems that while representing tuples as arrays at runtime is fine and dandy, perhaps at compile time they should be kept distinguished, i.e.
[number, string]and(number|string)[]should be considered mutually incompatible types.aluanhaddad commentedon Dec 24, 2016
The example actually typechecks because the signature of
sortisUnlike the example code from #13151,
fooinhas a tuple type.
pelotom commentedon Dec 24, 2016
I know, I'm saying that tuples should not be considered subtypes of
Array, in which case thesortmethod wouldn't be available on them. It makes no sense to sort a tuple.danvk commentedon Oct 4, 2017
FYI, you can work around this issue for Promises by using an object, rather than an array.
here's usage: