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

169
Vistas
Are these two generics syntax for Promise the same?

I'm new to TypeScript and learning about Generics. I've tried these syntax below and they work, so I'm thinking that they are the same.

Is my assumption correct?

using generic as in new Promise<number>

const promise = new Promise<number>((resolve, reject) => {
  //do smth...
});

using generic as in promise : Promise<number>

const promise : Promise<number> = new Promise((resolve, reject) => {
  //do smth...
});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

In short: in practice they probably act the same way

Long: yes there is a difference, the first example you gave passes the type number as a type to the class Promise and then the constructor returns a new instance of the type Promise, in that case the type of the variable is implicit, it's implied trough the value you give to it.

In your second example you instead do explicitly type your variable and then assign a generic Promise to it.

So: 1. Type of variable implied trough value, 2. Type explicitly given.

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