Search⌘ K
AI Features

TypeScript

Explore TypeScript as a superset of JavaScript and discover its features including static typing, class-based programming, modules, and access control. Understand how these features enhance Ionic app development, improve code organization, and enforce logic correctness with type annotations.

What is TypeScript?

TypeScript is a superset of the JavaScript language. This means it contains all of the features of JavaScript but also offers additional features not found within the language, such as:

  • Static typing
  • Class-based, object-oriented programming (prior to ES6)

Features of TypeScript

Some of the features that TypeScript introduces are as follows:

  • Modules
  • Data types
  • Classes
  • Access modifiers
  • Multiline strings
  • String interpolation

Modules

A module is simply a container for organizing and grouping our code that is then able to be exported and imported for use into another script, like so:

// importing module
import { IonicPage, NavController, NavParams } from 'ionic-angular';

// exporting module
export class AboutPage { /* class properties & methods contained in here */ }

Data types

Until ES6, JavaScript didn’t provide developers with the ability to specify the data type for their variables, so they would have to be declared, like so:

var firstName, lastName, age;

With TypeScript, we can explicitly declare the data types for each variable, known as type annotations, which help us ensure strict data and logic integrity in our coding.

If, for example, we were to ...