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

72
Views
ts tipo genérico condicional

Tengo un tipo genérico:

 type TResult<T> = { data: string[]; key: T[]; };

y quiero pasar T condicionalmente, proporcioné un ejemplo simple, quiero establecer el tipo dependiendo de la variable clave cuyo valor obtengo de la función proporcionada.

¿Tienes alguna idea de cómo puedo hacer eso? gracias de antemano.

¡ACTUALIZAR!: ejemplo completo

 type TKey = 'foo' | 'bar' | 'baz' type TType1 = { firstName: string lastName: string } type TType2 = { citry: string address: string } type TType3 = { age: number dob: Date } type TResult<T> = { data: string[]; key: T[] } function getQuery():TKey { const keys: TKey[] = ['bar', 'baz', 'foo'] return keys[Math.floor(Math.random() * 3)] } const key = getQuery() const result:TResult< /** I want to set the generic type depending on key */ >
about 4 years ago · Juan Pablo Isaza
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!