-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Implementation of concat
gives unexpected results
#39241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Feels strange to contrast with // returns 'T'
function tail<T extends any[]>(arg: [any, ...T]) {
const [_, ...result] = arg;
return result
} |
@ahejlsberg any thoughts on this one? |
Yeah, inferring |
BTW, the fact that we infer an array type for |
Actually, there's really no reason the unsound rule should be in effect for anything but the assignable and comparable relations. So, I think the fix is to disable it for the subtype relations, which causes us to preserve the full |
Here, TypeScript is okay with
concat1
returning[...T, ...U]
, but instead infers the type ofconcat2
to beT[number][]
.Notice
U
was not in the output type!As a result,
x1
has the type[1, 2, 3, 4, 5, 6]
andx2
has the type(1, 2, 3)[])
.The text was updated successfully, but these errors were encountered: