-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
When the initial element of the tuple is a rest element, it is not possible to correctly infer the type of the initial element. #56885
Comments
type T1 = [...string[], number, boolean]
const arr1: T1 = [2, true];
const arr2: T1 = ["", 2, true];
const arr3: T1 = [true]; // error
// ~~~~
// Type '[true]' is not assignable to type 'T1'.
// Source has 1 element(s) but target requires 2.
declare const arr: T1;
const head = arr[0]
// Actual: string | number | boolean
// Expected: string | number |
@fatcerberus I am making two assumptions:
@jcalz asserts here that "Yes, that type ( In other words, that my assumption 2 is incorrect. Certainly there are times when economy of calculation dictates using wider types. Other times it may just be expedient coding. Therefore I will withdraw my statement that this must be a bug, and instead assume it is a feature request. |
@13OnTheCode - As a feature request, I believe more explanation is required. Currently, you have your motivating example code listed in the suggestion section, and the motivating example and use cases sections are empty. Here is an example:
You could also give an algorithm that computes that. |
Yes, this assumption is incorrect. The PR that implemented mid/lead rest elements (#41544) specifically calls out the current indexing behavior, suggesting it's intentional (or at least a known-upfront design limitation). From #41544:
|
π Search Terms
initial element of the tuple is a rest element
β Viability Checklist
β Suggestion
π Motivating Example
π» Use Cases
#56883
The text was updated successfully, but these errors were encountered: