In https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#key-remapping-via-as, there is this example:
type Getters<Type> = {
[Property in keyof Type as `get${Capitalize<string & Property>}`]: () => Type[Property]
};
interface Person {
name: string;
age: number;
location: string;
}
type LazyPerson = Getters<Person>;
which makes LazyPerson { getName: () => string; getAge: () => number; getLocation: () => string; }.
I don't understand why is string & Property needed instead of just Property. AFAIK, keyof returns an union of PropertyKeys, and Capitalize requires its type parameter to be a subtype of string. So does string & Property somehow eliminate property keys that are not strings like number or symbol?
Generating types by re-using an existing type.