Closed
Description
Bug Report
π Version & Regression Information
- Compilation error
- This is the behaviour in every version I tried. Since 3.5.1
β― Playground Link
Playground link with relevant code
π» Code
interface IItem {
id: number
name: string
}
const item: IItem = {
id: 1,
name: 'item1'
}
const fun1 = (item: IItem, value: IItem[keyof IItem], name: keyof IItem) => {
item[name] = value
}
const fun2 = <T extends IItem>(item: T, value: T[keyof T], name: keyof T) => {
item[name] = value
}
π Actual behaviour
There's an error in fun1
. We can't do item[name] = value
otherwise we have the error Type 'string | number' is not assignable to type 'never'. Type 'string' is not assignable to type 'never'.
But the fun2 works perfectly.
π Expected behaviour
We should have the same behaviour in fun1 and fun2.