I have JSON objects with a large number of properties. I know some of the properties in advance, but the others are only known at runtime. All the objects have the same properties. What I would like to do is create an interface with the properties I do know, and access the others through an indexer.
For example, suppose I have the object {a: 1, b: '$', c: 12, d:53}
and I only know a
and b
in advance. I would like to do something like:
interface Record {
a: number;
b: string;
... rest of fields: number ...
}
Using an indexer won't work, adding [name: string]: number
to the interface causes an error, claimng that b is not a number.
Is there a way to do this?