I am facing an issue with matching an object of type foobar
to a generic object definition where each attribute is of the "number" type.
interface foobar {
a: number,
b: number
}
function baz(param: {[key: string]: number}) {
// some math stuff here
}
const obj: foobar = {
a: 1,
b: 2
};
baz(obj); // encountering error here
The TypeScript error message states:
TS2345: Argument of type 'foobar' is not assignable to parameter of type '{ [key: string]: number; }'. Index signature is missing in type 'foobar'.
Is there a solution to match the interface object to a generic object containing only number values?