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

177
Views
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 answers
Answer question

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 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!