Looking for a way to attach types to record names in a class that returns a Record. The current code snippet is as follows:
interface DataInterface {
bar: number;
foo: string;
fooBar: boolean;
}
export class MyClass {
public bar: number;
public foo: string;
public fooBar: boolean;
constructor(data: Record<string, DataInterface>) {
this.bar = data.bar; // ERROR: Type 'DataInterface' is not assignable to type 'number'.
this.foo = data.foo; // ERROR: Type 'DataInterface' is not assignable to type 'string'.
this.fooBar = data.fooBar; // ERROR: Type 'DataInterface' is not assignable to type 'boolean'.
}
}
How should I approach this issue given the possibility of numerous items in DataInterface
?