The parent class method updates the properties of the child class, but I get these error messages. How can I solve this problem.
index.ts code:
class A {
animate<
K extends keyof this,
T extends {
[key in K]: this[key] extends number ? this[key] : never
}
>(props: Partial<T>) {
const initialValue: Partial<T> = {}
const changeValue: Partial<T> = {}
for (let key in props) {
initialValue[key] = this[key]
changeValue[key] = props[key] - this[key]
}
// ...
}
}
class B extends A {
width: number
heigth: number
name: string
constructor() {
super();
this.heigth = 20
this.width = 20
this.name = 'B'
}
}
const b = new B();
b.animate({
width: 40,
heigth: 40
})
Error message:
ERROR in /project/app/index.ts(13,27) TS2536: Type 'Extract<keyof T, string>' cannot be used to index type 'this'.
ERROR in /project/app/index.ts(14,7) TS2322: Type 'number' is not assignable to type 'T[Extract<keyof T, string>] | undefined'.
ERROR in /project/app/index.ts(14,26) TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
ERROR in /project/app/index.ts(14,39) TS2536: Type 'Extract<keyof T, string>' cannot be used to index type 'this'.