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

80
Views
unión para matriz de objeto en mecanografiado?

¿Cómo extender una propiedad en una matriz de objetos en mecanografiado?

Tengo el siguiente código de reacción:

 interface List { id: string; } interface AppProps { list: List[]; } const App: React.FC<AppProps> = ({ list }) => { const [listCustom, setListCustom] = React.useState<List[]>([]); React.useEffect(() => { setListCustom([ { id: "3", newProperty: "new" //issue is here, how to extend List to have newProperty without modifying List? } ]); }, []); return ( <div className="App"> <h1>Hello CodeSandbox</h1> <h2>Start editing to see some magic happen!</h2> </div> ); }; export default App;

aquí

 React.useEffect(() => { setListCustom([ { id: "3", newProperty: "new" //issue is here, how to extend List to have newProperty without modifying List? } ]); }, []);

Tengo que establecer una nueva propiedad en List, pero no quiero modificar List porque está vinculado a AppProps. ¿Cómo puedo 'extenderlo' en la línea const [listCustom, setListCustom] = React.useState<List[]>([]); ?

No tiene sentido crear una List2 duplicada como

 interface List2 { id: string; newProperty: string }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede ampliar la interfaz de la lista:

 interface List2 extends List { newProperty: string; }

O puede usar un tipo de intersección:

 type List2 = List & { newProperty: string }

La interfaz no se puede hacer en línea, pero la intersección puede ser:

 const [listCustom, setListCustom] = React.useState<(List & { newProperty: string })[]>([]);
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!