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
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.
π Search Terms
rest
array
π Version & Regression Information
N/A
β― Playground Link
https://www.typescriptlang.org/play?#code/C4TwDgpgBAggTnAhiA6gS2ACwHIFEA2EAthAHbADOAPACoA0U2UEAHsGQCYVSkCuRAIwhwAfFAC8UGgG0AulABkUAN6FSAcywAuRgF8A3AChDoSLATJ0WbAAV8vCgWJlKtBk1btSXHvyGiJKGkAOlD4JFQMHCcScmp6RhEGUOCZWVkjE3BoAFkQcORAgsjrOwcYl2o+QWEGABYRTIBjAHtSCmAoRAQABgBGHTziwOk+hgAmBgBmDMMgA
π» Code
π Actual behavior
const arr01: MyArray = [1, 2, 3];
in the code is not validated as error.While in the following code, arr02 is validated as error.
π Expected behavior
const arr01: MyArray = [1, 2, 3];
in the code should be validated as error.Validation of MyArray should be an attempt of splitting it into two arrays to validate against each array rest operation.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: