Imagine having the following scenario where you need to create an object with keys that are transformed versions of the original type's values:
export type CCDTypes = {
AuthorisationCaseEvent: AuthorisationCaseEvent,
AuthorisationCaseField: AuthorisationCaseField,
CaseEvent: CaseEvent,
CaseEventToFields: CaseEventToField,
CaseField: CaseField,
EventToComplexTypes: EventToComplexType,
Scrubbed: Scrubbed
}
Currently, achieving this transformation manually can be done as follows:
export type COMPOUND_KEYS = {
AuthorisationCaseEvent: (keyof (AuthorisationCaseEvent))[],
AuthorisationCaseField: (keyof (AuthorisationCaseField))[],
CaseEvent: (keyof (CaseEvent))[],
CaseEventToFields: (keyof (CaseEventToField))[],
CaseField: (keyof (CaseField))[],
EventToComplexTypes: (keyof (EventToComplexType))[],
Scrubbed: (keyof (Scrubbed))[],
}
However, it is desired for COMPOUND_KEYS to be connected to CCDTypes for better type safety. Future additions to CCDTypes should prompt TypeScript to raise errors if corresponding data is not added to COMPOUND_KEYS.
This process will likely involve similar transformations in the future, hence the idea of creating a base type like CCDType type.
An attempted solution:
Record<keyof(CCDTypes), (keyof(keyof(CCDTypes)))[]>
has led to issues where the second type expects keys from an array (which makes sense considering keyof(CCDTypes)
returns an array).
How can this declaration be refined?