Is there a way to inform TypeScript that param
is not just a string
but of type RoleWithTier
(without using an explicit as
cast)?
enum Role {
USER = 'user',
ADMIN = 'admin'
}
enum Tier {
ENTRY = 1,
MAXIMUM = 10
}
type RoleWithTier = `${Role}.${Tier}`
const param = `${Role.USER}.${Tier.ENTRY}`
const selectAction = (rwt: RoleWithTier) {
// do stuff
}
selectAction(param) // Argument of type 'string' is not assignable to parameter of type '"user.1" | "user.10" | "admin.1" | "admin.10"'.(2345)