I'm currently working on creating a new method that wants to do an exemption of a specific enum value.
import { Overwrite } from 'utility-types';
enum Gender {
boy = 'boy',
girl = 'girl',
}
type Human = {
gender: Gender,
age: number,
}
type BoyGender = Exclude<Gender, 'girl'>;
type HumanBoy = Overwrite<
Human,
{
gender: BoyGender;
}
>;
export function accept(human: HumanBoy): void {
console.log(human)
}
accept({
gender: Gender.boy, // type error here
age: 2
})
When I use the enum of Gender again, I get a type error saying that
Types of property 'gender' are incompatible. Type 'Gender' is not assignable to type 'BoyGender'
Currently not sure why this is happening since BoyGender gets its value from Gender enum with the exemption of girl. Is there a way to pass this type error rather than creating a new enum with only boy?