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

201
Vistas
In flow, can you define an exact object type, using string types to define the keys

In flow, is it possible to define an exact object type, where the keys are also types?

In typescript you can accomplish this using strings, like...

export const userSettingsId = 'user-settings';

export type UserSettings = {
    favourites: boolean,
};

export const groupSettingsId = 'group-settings';

export type GroupSettings = {
    enabled: boolean,
};


export type Settings = {
    [userSettingsId]: UserSettings,
    [groupSettingsId]: GroupSettings,
};

const valid: Settings = {
    'user-settings': { favourites: true },
    'group-settings': { enabled: true }
}

const invalid1: Settings = {
    'user-settings': { favourites: true },
    'group-settings': { enabled: true },
    'friend-settings': { enabled: true }
}

const invalid2: Settings = {
    'user-settings': { favourites: true },
    'group-settings': { enabled: true, burritos: true },
}

You cannot use strings as types in flow, but you also do not seem to be able to use string literal types. Flow seems to expect types for keys to be an indexer which doesn't then support this.

This does not work for example...

export type UserSettingsId = 'user-settings';
export const userSettingsId: UserSettingsId = 'user-settings';

export type UserSettings = {|
    favourites: boolean,
|};

export type GroupSettingsId = 'group-settings';
export const groupSettingsId: GroupSettingsId = 'group-settings';

export type GroupSettings = {|
    enabled: boolean,
|};


export type Settings = {|
    [UserSettingsId]: UserSettings,
    [GroupSettingsId]: GroupSettings,
|};

The reason I want to do this, is so I can use the key on its own and ensure it is in sync with the object for when you lookup the key. Does anyone know if there is any solution to this in flow?

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