Closed
Description
TypeScript Version: Version 2.9.0-dev.20180426
Search Terms: keyof not assignable string
Code
//Just a minimal example, not what I am actually doing
function isKey<E> (str : string) : str is keyof E {
return true;
}
Expected behavior:
Should compile fine. The body of the type guard may actually correctly assert that str
is, indeed, keyof E
Works fine on TypeScript 2.8.3
Actual behavior:
error TS2677: A type predicate's type must be assignable to its parameter's type.
Type 'keyof E' is not assignable to type 'string'.
Type 'string | number | symbol' is not assignable to type 'string'.
Type 'number' is not assignable to type 'string'
Playground Link: Works on the playground
Related Issues: