Explain User defined data types in Typescript?

Following are the user defined data types in Typescript:

  • An array is a collection of the same data type. In TypeScript, we can also write arrays of values.
var list : number[] = [1,3,5];

                                   OR

var list : Array <number> = [1,3,5];

A tuple is a data type that includes two sets of values of different data types.

     // Declare a tuple

     let a: [string, number];

     // initialize it

     a = ["hi", 8, "how", 5];
  • An interface is a structure that acts as a contract in our application and defines the syntax for classes.
interface Calc { subtract (first : number,        

          second : number) : any  

          

          Let Calculator : Calc = {

           subtract (first : number, second : number)

           { return first - second; } }
  • Classes are used to create reusable components. They act as a template for creating objects.
  • Enums are a set of constant methods. TypeScript provides both string-based and numeric-based enums.
  • A function is a logical block of code used to organise the program.