Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

191
Views
¿Cómo se exporta el nombre de una propiedad y el tipo en lugar de definirlo en todas partes?

Digamos que tengo algo como esto:

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

y luego puedo usar en un componente como

 type Props = { style: Style }

pero en lugar de tener que definir eso en CADA componente, prefiero hacer

 type Props = { someRandomProp } & Style

y de esa manera no necesito agregar el accesorio como un tipo en todas partes

¿Cómo hago esto?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Puedes hacerlo casi como lo has mostrado:

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

después

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

Enlace del patio de recreo

about 4 years ago · Juan Pablo Isaza Report

0

Consulte la documentación oficial: Typescript Docs

 type Animal = { name: string } type Bear = Animal & { honey: boolean }

También puede usar interfaces en lugar de tipos para cada componente y hacer que se extiendan desde el tipo predefinido original como este:

 type Animal = { name: string } interface Bear extends Animal { honey: boolean }

Tenga en cuenta que la extensión no funciona entre tipos o de una interfaz a un tipo. Solo las interfaces y las clases pueden extenderse desde otra entidad.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!