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
Type definition with two rest operations for two arrays doesn't validated correctlyΒ #55783
T[] & {length: N} is not a valid tuple type, it's an array. So when you spread it, it's spread as an array, and your ArrayWithNPlusElements<T, N> type ends up being just T[]. You can see this when hovering over the type. When you use a proper tuple type you don't have this issue, that's why the suggested solution for the "N Tuple type" is #54740 (comment).
typescript should be able to report an error while declaring the type ArrayWithNPlusElements<T, N> as the error reported for type MixedArray<T, U> = [...T[], ...U[]], which is, A rest element cannot follow another rest element.,
or
typescript should be able to validate arr01 as error.
IMHO, this is not a question. It's the buggy behavior of typescript compiler/language service that
either
typescript should be able to report an error while declaring the type ArrayWithNPlusElements<T, N> as the error reported for type MixedArray<T, U> = [...T[], ...U[]], which is, A rest element cannot follow another rest element.,
or
typescript should be able to validate arr01 as error.
@MartinJohns I can't @ you because you blocked me. But I'm not talking about Tuple at all as a subset of the Array type. I don't use Typle much because I think it's immature, whereas you can call pop so that the tuple type of [string, string] becomes [string] or [] without realizing it.
Activity
MartinJohns commentedon Sep 19, 2023
T[] & {length: N}is not a valid tuple type, it's an array. So when you spread it, it's spread as an array, and yourArrayWithNPlusElements<T, N>type ends up being justT[]. You can see this when hovering over the type. When you use a proper tuple type you don't have this issue, that's why the suggested solution for the "N Tuple type" is #54740 (comment).KingMario commentedon Sep 19, 2023
Thanks MartinJohns
I'm just reporting a bug that
either
typescript should be able to report an error while declaring the type
ArrayWithNPlusElements<T, N>as the error reported fortype MixedArray<T, U> = [...T[], ...U[]], which is,A rest element cannot follow another rest element.,or
typescript should be able to validate arr01 as error.
typescript-bot commentedon Sep 22, 2023
This issue has been marked as "Question" and has seen no recent activity. It has been automatically closed for house-keeping purposes.
KingMario commentedon Sep 22, 2023
Hi Ryan Cavanaugh (@RyanCavanaugh)
IMHO, this is not a question. It's the buggy behavior of typescript compiler/language service that
either
typescript should be able to report an error while declaring the type ArrayWithNPlusElements<T, N> as the error reported for type MixedArray<T, U> = [...T[], ...U[]], which is, A rest element cannot follow another rest element.,
or
typescript should be able to validate arr01 as error.
@MartinJohns I can't @ you because you blocked me. But I'm not talking about Tuple at all as a subset of the Array type. I don't use Typle much because I think it's immature, whereas you can call pop so that the tuple type of [string, string] becomes [string] or [] without realizing it.