mirror of
https://github.com/oxc-project/oxc.git
synced 2026-09-14 19:36:11 +08:00
d61e3bf887
## Problem Named tuple rest elements bypass the parser's existing checks for optional elements after an array rest and for multiple array rests. For example, both of these declarations currently parse successfully even though TypeScript rejects them: ```ts type OptionalAfterRest = [...a: string[], b?: number]; type RestAfterRest = [...a: string[], ...b: number[]]; ``` The equivalent unnamed forms already produce TS1266 and TS1265, respectively. Mixed named and unnamed array rests have the same gap when either rest is named. ## Cause and change `parse_tuple_type` inspects `TSRestType.type_annotation` to decide whether an element is an array rest. For a named element, that annotation is a `TSNamedTupleMember`, and the actual type is stored in its `element_type`. Matching directly on the outer annotation therefore skips the array check and fails to track the rest element. Unwrap the named member with `as_ts_type()` before applying the existing classification. Named and unnamed elements then share the same validation and existing diagnostics: - An optional element after an array rest reports TS1266. - A second array rest reports TS1265, including mixed named and unnamed forms. The diagnostic spans continue to use the complete tuple elements, including their labels. The change borrows the underlying type without changing the AST representation or introducing allocations. ## Preserved behavior A rest marker alone does not make a spread an unbounded array. Fixed-tuple and generic variadic spreads continue to be accepted, including: ```ts type FixedBeforeOptional = [...a: [string], b?: number]; type RestBeforeFixed = [...a: string[], ...b: [number]]; type VariadicBeforeOptional<T extends unknown[]> = [...a: T, b?: number]; type RestBeforeVariadic<T extends unknown[]> = [...a: string[], ...b: T]; type MultipleVariadic<T extends unknown[], U extends unknown[]> = [...a: T, ...b: U]; ``` This change preserves the existing type-reference classification; it does not add type resolution or change how shadowed `Array` references are handled.