Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

240
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda