Skip to content
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

Tuple Spread Inconsistencies When Intersected #60539

Open
LukeAbby opened this issue Nov 19, 2024 · 1 comment
Open

Tuple Spread Inconsistencies When Intersected #60539

LukeAbby opened this issue Nov 19, 2024 · 1 comment

Comments

@LukeAbby
Copy link

πŸ”Ž Search Terms

Tuple, Intersection, Spread

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about tuples and arrays

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/C4TwDgpgBAKgrmANtAvFA2gZ2AJwJYB2A5gDRQB0lBcAtgEYQ7oC6zA3AFCiSwLICSBYI0wQAxsDwB7AlDTwk0AGRQA3lDA4pYAFxRs+YlAC+nDl3DQFyAEoRsAQTFj7mOb0XoAjOw4B6PygggD0oanpGc24rPghBYRxRCWkCO0dnV3drOKERcUkZb18AoKhQg0IiKAAfMNoGHHMLHmyAZU0IAEMAE3d0SnJs4sDSsowK4jIB8IaWZijLDwFcxPyU9pwu3rR+ymz4vOSZYdLQgAoJqtqZxgBKFiA

πŸ’» Code

type Tuple = [string, ...number[]];
type TupleIntersection = Tuple & { prop: string };


type TupleRestAccess = Tuple[1];
//   ^ number

type TupleIntersectionRestAccess = TupleIntersection[1];
//   ^ string | number


type TupleSpread = [...Tuple];
//     ^ [string, ...number[]]

type TupleIntersectionSpread = [...TupleIntersection];
//   ^ (string | number)[]

πŸ™ Actual behavior

TupleIntersection[1] and [...TupleIntersection] both seem to use an overly broad type, matching the number index signature instead of the more narrow spread signature.

What I mean is that TupleIntersection[1] behaves just like Tuple[number] does. This leads me to believe that the number index signature is synthesized correctly but the logic for numeric literals in the range of the spread signature aren't handled.

πŸ™‚ Expected behavior

I expected Tuple's behaviour to match TupleIntersection.

Additional information about the issue

No response

@jcalz
Copy link
Contributor

jcalz commented Nov 19, 2024

related to #59849, #59521, #45371, #42557, #40945

@LukeAbby LukeAbby changed the title Tuple Spread Inconsitencies When Intersected Tuple Spread Inconsistencies When Intersected Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants