Closed
Description
π Search Terms
spread tuple type narrowing
π Version & Regression Information
- This changed between versions 5.3.3 and 5.4.0-beta
- This changed in
5.4.0-dev.20240120
β― Playground Link
π» Code
declare function getT<T>(): T;
Promise.all([getT<string>(), ...getT<any>()])
.then((result) => {
// ^?
const head = result[0]; // 5.3: any, 5.4: string
// ^?
const tail = result.slice(1); // 5.3 any, 5.4: unknown[]
// ^?
tail satisfies string[]; // <-- new error in 5.4
});
Additional information about the issue
More of a 'change report' than a 'bug report', I don't think this was part of the 5.4 beta announcement.
Activity
errorType
whenany
is spread #57116Andarist commentedon Feb 13, 2024
This can be bisected to: #57031 and it's a bug.
When hovering over
all
we can see this:So how
[string, ...any[]]
was converted into[string, ...unknown[]]
here? The reason is that nowinstantiateMappedTupleType
has this?? unknownType
fallback when computingnewElementTypes
.But it's not consistent with how mapped types continue to work today:
So the problem is that what we see in the original repro is actually not a true
any
but rather anerrorType
. And if we play around with it we can see the change in the behavior:The PR to which this has been bisected improves the situation (the output should be a tuple and not an
any
/errorType
) but accidentally maps the thing to[string, ...unknown[]]
.Why the
errorType
has crawled into all of this though? Well, I already have a fix for this π : #57116[-][TS 5.4.0-beta] Tuple type members being perserved[/-][+][TS 5.4.0-beta] Tuple type members being preserved[/+]