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

196
Views
¿Cómo convertir la interfaz personalizada a Record<string, unknown>?

Dado el siguiente código de ejemplo

 interface MyInterface { foo: string; } function doSomethingWith(x: Record<string, unknown>) { /* ... */ } const myInterface: MyInterface = { foo: 'bar' }; doSomethingWith(myInterface);

No es posible pasar la variable a la función porque

El argumento de tipo 'MyInterface' no se puede asignar al parámetro de tipo 'Record<string, unknown>'. Falta la firma de índice para el tipo 'string' en el tipo 'MyInterface'.(2345)

Resolví el problema convirtiendo la variable

const myInterfaceAsRecord = (myInterface as unknown) as Record<string, unknown>;

y me gustaría saber si hay formas "mejores" de pasar la interfaz a la función.

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

0

Simplemente use el type en lugar de la interface

 type MyInterface = { foo: string; } function doSomethingWith(x: Record<string, unknown>) { /* ... */ } const myInterface: MyInterface = { foo: 'bar' }; doSomethingWith(myInterface);

Ver esta respuesta para más contexto

about 4 years ago · Juan Pablo Isaza Report

0

Una opción sería extender la interfaz desde el registro:

 interface MyInterface extends Record<string, unknown> { foo: string; } function doSomethingWith(x: Record<string, unknown>) { /* ... */ } const myInterface: MyInterface = { foo: 'bar' }; doSomethingWith(myInterface);
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!