export interface Cookies {
Token: string;
SessionID: string;
UserID: string;
}
type property = keyof Cookies
// property is "Token" | "SessionID" | "UserID"
export const COOKIE_PROPERTIES: Record<property, property> = {
Token: 'Token',
SessionID: 'SessionID',
UserID: 'UserID',
};
I aim to ensure the COOKIE_PROPERTIES, where each property matches its value.
Token = 'Token'
Is there a method to create a property-value mapping from keys of the interface? Possibly through reflection?
Update
I successfully tackled this issue by employing a solution similar to C#'s nameOf.
export function nameOf<T>(name: Extract<keyof T, string>): string {
return name;
}
nameOf<Cookies>('Token') // = 'Token'