Skip to content

Indexing constraints on mapped type should use the constraint type  #12315

Closed
@mhegazy

Description

@mhegazy

when indexing into a mapped type using a key that is constraint to the same constraint type, indexing should be allowed. consider:

type Optional<T> = {[K in keyof T]?: T[K]}; 

function setFromOther<T, K extends keyof T>(obj: T, k: K, other: Optional<T>) {
    obj[k] = other[k];  // K is not constraint to keyof Optional<T>
}

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions