Declare variable types in TypeScript


JavaScript is a dynamically typed language. While this makes declaring variables easy, it can in some cases lead to unexpected results. The static type system in TypeScript enables you to describe the shape of an object, providing better documentation, and allowing TypeScript to validate that your code is working correctly. In TypeScript, declarations of namespaces, classes, properties, functions, variables, and other language entities associate types with those entities. The way that a type is formed and associated with a language entity depends on the kind of entity. This module introduces some of the available types and shows how to associate them with variables. Later modules examine how interfaces, functions, and classes use static typing.

Learning objectives

In this module, you will learn how to:

  • Explain the advantages of declaring typed variables in TypeScript.
  • Declare variables using primitive types.
  • Declare variables using object types.
  • Declare variables using union and intersection types.


  • Familiarity with JavaScript.
  • Familiarity with declaring variables using let and const in JavaScript.
  • Basic knowledge of TypeScript.
  • Installed software: