I wish to restrict the assignable types of an object to a specific type. Example, an object where all keys must have number values, such as below:
interface NumberMap {
[key: string]: number;
}
This works for enforcing the value restriction however I then won't be able to determine what keys actually exist inside the map variable.
const map: NumberMap = {
one: 1,
two: 2,
three: 3,
};
// no error, but incorrect, this key does *not* exist
const lol = map.weoiroweiroew;
// Also cannot do this
type MyKeys = keyof map;
Is there a way to enforce an index signature without losing the information of what keys the object implementing that signature has?