Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

union types typescript

/*
TypeScript allows us to use more than one data type for a variable 
or a function parameter. This is called union type.
*/
let code: (string | number);
code = 123;   // OK
code = "ABC"; // OK
code = false; // Compiler Error

let empId: string | number;
empId = 111; // OK
empId = "E111"; // OK
empId = true; // Compiler Error
 
PREVIOUS NEXT
Tagged: #union #types #typescript
ADD COMMENT
Topic
Name
6+1 =