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

217
Views
¿Por qué mecanografiado no sabe que verifiqué el tipo de objeto?

Quiero construir tal función:

 const recursionProxy = <T extends object>(subject: T) => new Proxy(subject, { get(target, key: keyof T) { const nestedSubject = target[key]; if (typeof nestedSubject === "object") { return recursionProxy(nestedSubject); } return nestedSubject ?? target._ ?? "Message not set"; }, });

pero bajo la línea recursionProxy(nestedSubject); hay un error que dice

 [i] Argument of type 'T[keyof T]' is not assignable to parameter of type 'object'.

por qué mecanografiado no tiene en cuenta que la declaración if, dentro de la declaración if nestedSubject es de tipo object

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

0

Parece funcionar si usa un predicado de tipo:

 const isObject = (f: any): f is object => { if(typeof f === "object") return true; return false; } const recursionProxy = <T extends object>(subject: T) => new Proxy(subject, { get(target, key: keyof T) { const nestedSubject = target[key]; if (isObject(nestedSubject)) { return recursionProxy(nestedSubject); } return nestedSubject ?? target._ ?? "Message not set"; }, });

Enlace

También se puede agregar una verificación nula en el predicado, si es necesario:

 const isObject = (f: any): f is object => { if(f === null) return false; if(typeof f === "object") return true; return false; }
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!