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

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. TypeScript Mastery

Lesson 25 of 56 · Typescript

Promises & Generics

Duration: 15 minutes

Generic Promise Helper

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

wrap(5).then(n => console.log(n * 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.

Previous: Async/Await with TypesNext: Custom Error Types