Here is a simple example:
typedef Bar = { x: number; y: boolean }
type Foo = { [key: string]: Bar }
const foo: Foo = {
baz: { x: 3, y: true }
}
// This will pass without any issues
console.log(foo['baz'])
// Error message stating: Property 'baz' does not exist on type '{ [key: string]: { x: number; y: boolean; }; }'.
console.log(foo.baz)
I am looking for the last line to be able to check the type correctly and have the type of foo.baz
labeled as Bar
. If index signatures are not suitable for achieving this type of definition, what would be the correct approach? Is it even feasible?