Skip to content

homomorphic mapped tuple doesn't preserve parallel tuple #46741

Closed
@tadhgmister

Description

@tadhgmister

Bug Report

🔎 Search Terms

homomorphic mapped tuples, variadic tuple, parallel lists, zip tuples together, pipeline, compose function, keyof array.

🕗 Version & Regression Information

  • This is the behaviour in every version of the playground from 4.0.5 up to nightly v4.6.0-dev2021-11-05
    • This is not applicable before 4.0.5 since tuple spread [A,...V] doesn't exist that far back
    • and I reviewed the FAQ for entries about mapped types, I don't have primitives here.

⏯ Playground Link and Explanation

Playground link with relevant code

💻 Code

interface A{a:any}
interface B{b:any}
interface C{c:any}

type Combine<X,Y> = {[K in keyof X]: [X[K], Y[K&keyof Y]]}
type XX = [A,B,C]
type YY = [1,2,3]
declare const example_value: [["x", "y"], [A, 1], [B, 2], [C, 3]]

let works_as_expected: Combine<['x',...XX], ['y',...YY]> = example_value
// let works_as_expected: [["x", "y"], [A, 1], [B, 2], [C, 3]]

type Alias<X extends any[],Y extends any[]> = Combine<['x',...X],['y',...Y]>
let doesnt_work: Alias<XX,YY> = example_value
// let doesnt_work: [["x", "y"], [A, "y"], [B, 1], [C, 2]]

🙁 Actual behavior

works_as_expected is correctly the type [['x','y'], [A, 1], [B, 2], [C, 3]] but doesnt_work which is basically defined the exact same way except the spreading is done inside another type alias gives a totally different and incorrect type [["x", "y"], [A, "y"], [B, 1], [C, 2]]

🙂 Expected behavior

example should compile without errors, the type of doesnt_work should be the same as works_as_expected.

Metadata

Metadata

Assignees

Labels

Working as IntendedThe behavior described is the intended behavior; this is not a bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions