Encountering a Typescript issue where it claims that type A is not compatible with type A, even though they are identical:
Check out this playground link for the code snippet in context:
declare interface ButtonInteraction {
user: any;
customId: string;
reply: (message: string) => void
}
enum TranslatorLangs {
FR = 'fr',
EN = 'en',
}
export class UserService {
public async setUserLocale(user: any, locale: TranslatorLangs): Promise<any> {
user.locale = locale;
}
}
export interface ButtonHandlerInterface {
commandName: string;
handle<T = unknown>(interaction: ButtonInteraction, value: T): void | Promise<void>
}
export default class MbtiCommandHandler implements ButtonHandlerInterface {
public commandName = 'setLocale';
private userService: UserService = new UserService();
async handle<TranslatorLangs>(interaction: ButtonInteraction, value: TranslatorLangs): Promise<void> {
this.userService.setUserLocale(interaction.user, value);
// ^^^^^
// Argument of type 'TranslatorLangs' is not assignable to parameter of type 'TranslatorLangs'
interaction.reply(`Ok, so it will be ${interaction.customId}`);
return interaction.reply('ok');
}
}