I have a problem:
- I do not assign for value of variable temp as code below
Please, how to assign value to variable temp
Following code below:
interface Base {
a: number;
b: number;
c: string;
}
interface Child extends Base {
d: string;
}
const data: Child = {
a: 1,
b: 2,
c: "1",
d: "2"
}
function check<T extends Base>(obj: T, key: string) {
const keys: any[] = Object.keys(obj);
type dataTypes = keyof T;
for (let m in keys) {
// error:
// Type 'string' is not assignable to type 'keyof T'.
// Type 'string' is not assignable to type '"a" | "b" | "c"
const temp: dataTypes = m; //error
}
}
function test(data: Base) {
check(data, "d")
}
keysis of typestring[]notdataTypes[]