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.

Advanced Generics – Variadic Tup | TypeScript Mastery lesson | BraveProgrammer
  1. Courses
  2. /
  3. TypeScript Mastery

Lesson 45 of 56

·Typescript

Advanced Generics – Variadic Tuple Types

25 minutes

Course progress80%

Variadic Tuples (TS 4.0+)

function concat<T extends any[], U extends any[]>(...args: [...T, ...U]): [...T, ...U] {
  return args as any;
}

const result = ([, ], [, , ]); 
concat
1
2
'a'
'b'
'c'
// inferred as [number, number, string, string, string]

Generic Constraints using extends and infer

type ReturnType<T> = T extends (...args: any[]) => infer R ? R : never;
type Fn = (x: number) => string;
type R = ReturnType<Fn>; // string

Mapping over tuple elements

type MapTuple<T extends any[], F> = { [K in keyof T]: F };
type Numbers = MapTuple<[1, 2, 3], string>; // [string, string, string]

Info

Variadic tuples enable type‑safe function pipelines where the output shape depends on the input shape.
Make it stickPractice what you've learned1 quiz · 3 practical tests · Optional activities from TypeScript MasteryBrowse activities
Previous lessonPublishing a TypeScript Library to npmContinue to lesson 46Template Literal TypesBack to TypeScript Mastery curriculum