The following code snippet reports an error Type 'string' is not assignable to type 'never'.(2322) in the line obj[prop] = value and I struggle understanding why?
interface fooType {
s: string,
n: number,
}
function bar(value: string, obj: fooType, prop: keyof fooType) {
if (typeof value === 'string') {
obj[prop] = value;
}
}
const foo = {s: '', n: 0};
bar('s', foo, 's');
console.log(foo);