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

188
Vistas
Using union type as function parameter

I have a type defined like so:

type FieldToAction = {
            [key in ApiActions]: ((field: Field) => void) | ((field: Field, fieldValue: FieldValue) => void)
        }

where FieldValue is a union of types:

type FieldValue = string | string[] | AssigneeValue | PriorityValue

I have a variable object where I then declare the functions set by the above types:

const fieldToAction: FieldToAction = {
            .
            .
            .
            "SET_DESCRIPTION": (field: Field, fieldValue: string) => field.setDescription(fieldValue),
            "SET_LABELS_VALUE": (field: Field, fieldValue: string[]) => field.setValue(fieldValue)
        };

This produces an error where the values in the object are not of type FieldToAction, I kind of understand why since I am now constraining the parameter to be a string or string[].

My question is: Is there a way of still using the union of types' type and constraining the value in the parameter?

Thank you

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