Skip to content

Indexing mapped type with keyof type param #16018

Closed

Description

TypeScript Version: 2.2.2

Code

On playground

type Eg = { foo: string, bar: number }

type VariantRec<T> = {[K in keyof T]: { type: K, value: T[K] }}
type Alpha1 = VariantRec<Eg>[keyof Eg]

type VariantType<T> = VariantRec<T>[keyof T]
type Alpha2 = VariantType<Eg>

const assignable12: Alpha2 = null as Alpha1
const assignable21: Alpha1 = null as Alpha2

Expected behavior:

Types Alpha1 and Alpha2 should be the identical.

Actual behavior:

Alpha2 incorrectly becomes: { type: 'foo' | 'bar', value: string | number }
It should be: { type: 'foo', value: string } | { type: 'bar', value: number }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions