Skip to content

Indexing mapped type with keyof type param #16018

Description

@liam-goodacre-hpe

TypeScript Version: 2.2.2

Code

On playground

typeEg={foo: string,bar: number}typeVariantRec<T>={[KinkeyofT]: {type: K,value: T[K]}}typeAlpha1=VariantRec<Eg>[keyofEg]typeVariantType<T>=VariantRec<T>[keyofT]typeAlpha2=VariantType<Eg>constassignable12: Alpha2=nullasAlpha1constassignable21: Alpha1=nullasAlpha2

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 }

Metadata

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