The overrideDefaults method of OptionCloner<O> uses an any type to represent an object that contains a subset of the properties of O. This prevents compilation-time check of the property names. In order to solve this and other similar problems, TypeScript has two operators defined on types: the , keyof O index type query operator and the, O[k] indexed access operator.
Furthermore, keyof O returns the subtype of string that just contains all public property names of O. Thus keyof GraphicStyle is the following type:
"pencilType"|"pencilWidth"|"foregroundColor"|"backgroundColor"
The pencilType shown in the preceding code contains the names of all public properties of GraphicStyle. Similarly, GraphicStyle["pencilWidth"]) is the type of the property of GraphicStyle whose property name is pencilWidth, which...