Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

134
Vistas
How can i declare a function as async in a Interface?

I have an Interface and a Class which implements the methods, I didn't find a answer to my Problem by now. I have a function defined myAsyncFunction() in the Interface and i want to make it async:

export interface State {
  state: Class;

  myAsyncFunction(): any;
}
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

TypeScript doesn't care if a function uses the async keyword. It only cares that it is a function, what arguments it takes, and what the return value is.

The only significance of the async keyword in that context is that the function will return a promise … which will be matched by any.

about 4 years ago · Juan Pablo Isaza Denunciar

0

To the caller, an async function is just a function that returns a promise:

export interface State {
  state: string;
  myAsyncFunction(): Promise<any>;
}

const state : State = {
  state: 'foo',
  myAsyncFunction: async () => 'bar'
};
about 4 years ago · Juan Pablo Isaza Denunciar

0

Function is async when returns a Promise. Here is example how to define async function in interface:

interface Foo {
    bar: () => Promise<void>
}

Instead of void you can use any return type you want and of course you can use any parameters you want, for example:

interface Foo {
    bar: (test: string) => Promise<boolean>
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda