CodesJava

Easy learning with example program codes

TypeScript Union Type tutorial


TypeScript union type:

TypeScript Union Type provides the facility to combine one or two types for a variable. The pipe symbol (|) is used to combine the two or more data types.

Syntax:

var varName: dataType1|dataType2|dataType3

Example:

function unionTest(value:string|number):void{
  console.log(value); 
}
unionTest("Jai");
unionTest(123);

Try it:

JS Bin on jsbin.com

Please follow and like us:


Copyright © 2019 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki