In my TypeScript file I have this object:
export const GLOBAL_MESSAGES = {
USER: {
EXISTS: 'User already Exists',
SUCCESSFULLY_REGISTERED: 'User successfully is registered',
},
TEST: '123',
}
also in try to create a specific response shape:
export interface UserResponseInterface extends UserInterface {
message: keyof typeof GLOBAL_MESSAGES.USER;
}
const a: UserResponseInterface = {
message: GLOBAL_MESSAGES.USER.EXISTS,
password: 'asd',
};
Expected result: when I type:
message: GLOBAL_MESSAGES.USER.EXISTS,
I shouldn’t get any TS complaints like now:
TS2322: Type string is not assignable to type
"EXISTS" | "SUCCESSFULLY_REGISTERED"
1