Closed
Description
TypeScript Version: 2.2.0
Code with unexpected type error:
export function set<T, K extends keyof T>(obj: T, key: K, value: T[K]) {
return Object.assign(obj, {
[key]: value,
});
}
Expected behavior:
No type errors because K
should is a subtype of keyof T
. It works if key: keyof T
and even key: K & keyof T
.
Actual behavior:
Type error:
A computed property name must be of type 'string', 'number', 'symbol', or 'any'.