While experimenting with TypeScript in the TS playground, I am attempting to create a small utility function but encountering issues with TypeScript's type checking.
The error message states that my argument is
not assignable to parameter of type 'Partial<this["t"]>'
export function x<T, K extends keyof T, M extends T[K]>(obj: T, prop: K, extension: Partial<M>) {
obj[prop] = {
...obj[prop],
...extension
}
}
type T = {
a: string,
b: number
}
class C {
t: T = { a: 'a', b: 3 }
constructor() {
x(this, 't', { b: 42 }) // error is here
}
}
Is there a workaround for this issue? Perhaps using ThisType
? Any suggestions would be appreciated.