I need to have an object that can have any property of one type but it also needs to have specific, predefined properties of another type.
For example:
const foo = {
$id: 'id',
bar: 123
}
$id
is predefined and needs to be a string. bar
is not predefined, and needs to be a number.
The type definition, in concept, would look like this:
type Foo = {
$id: string;
[key: string]: number;
}
This type does not work. Is there any way to construct the desired type? I have tried
type Foo = {
[key: string]: number;
} & { $id: string };
but that does not work either.