I want to use a boolean variable in a arithmetic operation in typescript, but the compiler complains: "The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type."
class User {
hasFoo: boolean;
};
let user = new User();
let amount : number = BASE + FOO_FACTOR * user.hasFoo
I know that I can cast my boolean to the type <any> and it's working:
let amount : number = BASE + FOO_FACTOR * <any>user.hasFoo
But is it the best solution?
let amount: number = user.hasFoo ? BASE + FOO_FACTOR : BASE;orlet amount: number = BASE + (user.hasFoo ? FOO_FACTOR : 0);