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

163
Vistas
How to make two enums have the same keys?

I have these two enums:

enum foo {
   bar,
   baz
}

enum fiz {
   ...
}

How can I make sure, that fiz has the same keys as foo? I tried adding an interface, but no luck with assigning.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can use a map.

enum foo {
  bar,
  baz,
}

const fiz = new Map<foo, string>([
  [foo.bar, 'value1'],
  [foo.baz, 'value2'],
]);

OR you can do something like this

enum Foo {
    A = "ActivityCode.Foo.A",
    B = "ActivityCode.Foo.B",
    C = "ActivityCode.Foo.C",
}

enum Bar {
    A = "ActivityCode.Bar.A",
    B = "ActivityCode.Bar.B",
    C = "ActivityCode.Bar.C",
}

enum Baz {
    A = "ActivityCode.Baz.A",
    B = "ActivityCode.Baz.B",
    C = "ActivityCode.Baz.C",
}

const ActivityCode = {
    Foo,
    Bar,
    Baz,
};

console.log(ActivityCode.Foo.A);

reference

about 4 years ago · Juan Pablo Isaza Denunciar

0

Based on your comment, I think this is approach will work well for you:

TS Playground

const keys = ['foo', 'bar', 'baz'] as const;
type Key = typeof keys[number]; // "foo" | "bar" | "baz"

type ObjectWithSameKeys<ValueType> = Record<Key, ValueType>;

const labels: ObjectWithSameKeys<number> = {
  foo: 1,
  bar: 2,
  baz: 3,
};

const names: ObjectWithSameKeys<string> = {
  foo: 'one',
  bar: 'two',
  baz: 'three',
};
about 4 years ago · Juan Pablo Isaza Denunciar
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