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

104
Views
Implementación de propiedades de tipo fuerza de clase mecanografiada

Dado un tipo:

 type TestType = { a?: string; b?: number; c?: boolean; };

Quiero crear una clase que implemente TestType con todos sus nombres de propiedades donde los tipos podrían ser diferentes.

Si no, genera un error.

Lo he intentado con Pick , Required , etc. sin éxito.

Ejemplo (error):

 /* Error, not all TestType properties are implemented */ class TestClass implements TestType {}

Ejemplo (correcto):

 class TestClass implemenets TestType { a?: boolean; // Different type b?: number; // Same type c?: string; // Different type }

¿Se puede lograr esto con Typescript?

¡Gracias!

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

0

Podemos hacer un type de utilidad llamado ToAny para esto:

 type ToAny<T> = {[K in keyof T]: any}

Uso:

 class TestClass implements ToAny<TestType> {} class TestClass2 implements ToAny<TestType> { a?: boolean; // Different type b?: number; // Same type c?: string; // Different type }
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!