Due to limitations in TS syntax, I am unable to use the following:
anObject['aKey'] = 'aValue';
To work around this issue, I have created the interfaces below and made all objects inherit from them:
interface KeyIndexable {
[key: string]: any;
}
interface ObjectA extends KeyIndexable {
a: string;
b: number;
}
Now, when attempting to define a generic function variable like so:
let x: <T extends KeyIndexable>(t: T) => void;
x = (a: ObjectA) => console.log('x');
I am encountering an error stating
Type KeyIndexable is missing the following properties from type ObjectA
.
How can this be resolved?