Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

234
Views
Typescript: How to be typesafe on exempting an enum value in new interface

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?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!