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 45 of 56 · Typescript

Advanced Generics – Variadic Tuple Types

Duration: 25 minutes

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.

Previous: Publishing a TypeScript Library to npmNext: Template Literal Types