Creates a new Record type from the literal properties of a type T, assigning their values
the to the type U.
This can be useful for creating interfaces from the keys of an enum so that the keys are
available at runtime for meta-programming purposes, while both tying the properties of the
generated type to the enum keys and remaining as DRY as possible.
enumQUERY_KEY { id, name, created, updated } // type of QUERY_KEY -> { // [x: number]: number; // readonly id: number; // readonly name: number; // readonly created: number; // readonly updated: number; // } interfaceQueryRecordextendsLiteralsRecord<typeofQUERY_KEY, string> { } // type of QueryRecord -> { // readonly id: string; // readonly name: string; // readonly created: string; // readonly updated: string; // } // And for an interface with writable properties, use the following: interfaceQueryRecordextendsReadWrite<LiteralsRecord<typeofQUERY_KEY, string>> { } // type of QueryRecord -> { // id: string; // name: string; // created: string; // updated: string; // }
Creates a new
Record
type from the literal properties of a typeT
, assigning their values the to the typeU
.This can be useful for creating interfaces from the keys of an
enum
so that the keys are available at runtime for meta-programming purposes, while both tying the properties of the generated type to the enum keys and remaining as DRY as possible.