TypeScript 1.4 makes use of unions to combine one or two types. It can be done using a pipe symbol (|) denote a Union Type.
Example: Union Type Variable
In the example above, the variable’s type is union. It means that the variable can consists of either a number or a string as its value.
Its result is as below −
Example: Union Type and function parameter
We can see a function disp() which accepts either of the type string or a string array.
The result is as below −
Union types are applicable to arrays, properties and interfaces. The below example illustrates the use of union type with an array.
Example: Union Type and Array
In above program, an array is declared which represents either a numeric collection or a string collection.
Its result is as follows −
TypeScript Related Interview Questions
|HTML 5 Interview Questions||Hibernate Interview Questions|
|Angular JS Interview Questions||JavaServer Faces (JSF) Interview Questions|
|Bootstrap Interview Questions||CSS Advanced Interview Questions|
|Advanced jQuery Interview Questions||Spring Boot Interview Questions|
|Spring Batch Interview Questions||AppleScript Interview Questions|
|GitHub Interview Questions||Bootstrap 4 Interview Questions|
All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.