RecipesChapter 2: Basic Types

Choosing the Right Object Type

Recipe 2.9 from The TypeScript Cookbook

let obj: object;
obj = 32; // Error
obj = "Hello"; // Error
obj = true; // Error
obj = () => { console.log("Hello") };
obj = undefined;  // Error
obj = null; // Error
obj = { name: "Stefan", age: 40 };
obj = [];
obj = /.*/;
Open in TypeScript Playground →