Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Promises & Generics | TypeScript Mastery lesson | BraveProgrammer
  1. Courses
  2. /
  3. TypeScript Mastery

Lesson 25 of 56

·Typescript

Promises & Generics

15 minutes

Course progress45%

Generic Promise Helper

function wrap<T>(value: T): Promise<T> {
  return Promise.resolve(value);
}

wrap(5).then( => .(n * )); 
n
console
log
2
// 10

Promise.allSettled

Returns a uniform shape regardless of fulfillment or rejection.

const results = await Promise.allSettled([
  fetch('/a'),
  fetch('/b'),
]);

results is typed as PromiseSettledResult<Response>[].

Creating a typed delayed function

function delay<T>(ms: number, value: T): Promise<T> {
  return new Promise(resolve => setTimeout(() => resolve(value), ms));
}

Info

Generics let you preserve the value’s type through asynchronous pipelines.
Make it stickPractice what you've learned1 quiz · 3 practical tests · Optional activities from TypeScript MasteryBrowse activities
Previous lessonAsync/Await with TypesContinue to lesson 26Custom Error TypesBack to TypeScript Mastery curriculum