I'm relatively new to using TypeScript and I am trying to define a type similar to the following:
type U = { [key: string]: number }; // any string for the keys
type T = { [key: string]: U }; // again, any string for the keys
Here's an example of how it would be used:
const test: T = {
'aaa': {
'xxx': 777,
'yyy': 888,
'zzz': 999 // expecting an error here
},
'bbb': {
'xxx': 444,
'yyy': 555,
'ooo': 666 // expecting an error here
}
};
Is there a more sophisticated signature that can ensure all properties of U within T will have the same keys?