Write Getters<T>: turn { name: string } into { getName: () => string }.
For each string key of T, Getters<T> has a method named get followed by the capitalized key, returning that property's type. Every getter is required, even for an optional property, whose getter returns undefined when the value is missing. Then write createGetters(source), which builds the getters at runtime and reads the current value on each call.
type Getters<T> = {}; function createGetters<T extends object>(source: T): Getters<T> { // { name: "Ada" } becomes { getName: () => "Ada" }} // Getters<{ name: string; age?: number }>// // { getName: () => string; getAge: () => number | undefined }The answer
Write it yourself first. Then compare it with a reference solution and the checks it passes.
Checking your sign-in…