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

196
Vistas
How do you export a prop name and the type instead of defining it everywhere?

Say I have something like this:

export type Style = Pick<
  React.CSSProperties,
  "margin" | "marginBottom"
>

and I can then use in a component like

type Props = {
   style: Style
}

but instead of having to define that in EVERY component I'd rather do

type Props = {
  someRandomProp
} & Style

and that way I don't need to add the prop as a type everywhere

how do I do this?

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

0

You can do it very nearly as you've shown:

export type Style = Pick<
    React.CSSProperties,
    "margin" | "marginBottom"
>;
export type StyleProp = {
    style: Style
};

then

import { StyleProp } from "./somewhere";
// ...
type Props = {
    someRandomProp: string; // or whatever
} & StyleProp;

Playground link

about 4 years ago · Juan Pablo Isaza Denunciar

0

Refer to the oficial documentation: Typescript Docs

type Animal = {
  name: string
}

type Bear = Animal & { 
  honey: boolean 
}

You can also use interfaces instead of types for each component and make them extend from the original predefined type like this:

type Animal = {
  name: string
}

interface Bear extends Animal {
  honey: boolean
}

Notice that extending doesn't work between types or from an interface to a type. Only interfaces and classes may extend from another entity.

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