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

270
Views
Texto mecanografiado: Cómo aceptar 2 tipos diferentes

Tengo un método getRoute que toma un video . El video es del tipo LiveVideo o RecordedVideo . Mi problema es que el campo getLiveID solo está en LiveVideo , por lo que obtengo la property de problema del editor getLiveID does not exist on type RecordedVideo . ¿Cuál es la forma de evitar esto? Quiero usar 1 método para manejar ambos y manejar la lógica condicional dentro.

 getRoute(video: LiveVideo | RecordedVideo) { if (video.getLiveID) { /// } else { /// } }
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Puedes usar instancia de :

 getRoute(video: LiveVideo | RecordedVideo) { if (video instanceof LiveVideo) { // "video" is of type LiveVideo here... } else { // ... } }
about 4 years ago · Juan Pablo Isaza Report

0

Puede verificar qué tipo tiene usando in . Por ejemplo:

 getRoute(video: LiveVideo | RecordedVideo) { if ("getLiveId" in video) { // treat as LiveVideo } else { // as RecordedVideo } }
about 4 years ago · Juan Pablo Isaza Report

0

type LiveVideo = { getLiveID: Function, id: string } type RecordedVideo = { id: string } function getRoute(video: LiveVideo | RecordedVideo) { if ((video as LiveVideo)?.getLiveID) { /// } else { /// } }
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!