RecipesChapter 2: Basic Types

Understanding Interfaces Versus Type Aliases

Recipe 2.4 from The TypeScript Cookbook

// Some data we collect in a web form
interface FormData {
  name: string;
  age: number;
  address: string[];
}

// A function that sends this data to a backend
function send(data: FormData) {
  console.log(data.entries()) // this compiles!
  // but crashes horrendously in runtime
}
Open in TypeScript Playground →