RecipesChapter 4: Generics

Getting Rid of any and unknown

Recipe 4.3 from The TypeScript Cookbook

function pairs<T>(a: T, b: T): [T, T] {
  return [a, b];
}

const c = pairs(1, "1");
//                  ^
// Argument of type 'string' is not assignable to parameter of type 'number'
Open in TypeScript Playground →