Index types | Typescript
With index types, you can get the compiler to check code that uses dynamic property names.
First is keyof T, the index type query operator.
For any type T, keyof T is the union of known, public property names of T.
The second operator is T[K], the indexed access operator.
You just have to make sure that the type variable K extends keyof T.