Skip to content

T[keyof T] assignable to T[K] #17166

@olegdunkan

Description

@olegdunkan

TypeScript Version: 2.4.0 / nightly (2.5.0-dev.201xxxxx)

Code

// A *self-contained* demonstration of the problem follows...
function f<T, K extends keyof T>(obj: T, k: K, value:T[K]) {
  for (let key in obj) {
    value = obj[key];
    break;    
  } 
  return value;
}

f({ x: 1, y: "" }, 'y', "1").charAt(0); //runtime error

Expected behavior:
Compiler error
Actual behavior:
Runtime error

Metadata

Metadata

Assignees

No one assigned

    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