Word
union type
Definition
compound. a way to store data that can hold one of several different types of information. It is like a box that can hold either a number or a word, but only one at a time.
compound. a data type that allows a single memory location to store values of different types at different times. In programming, it represents a value that could be any one of several specified types.
Examples
“The programmer used a union type to handle both strings and numbers.”
“When writing the function, she defined a union type so the input could be either a single user ID or an array of IDs.”
“In TypeScript, a union type is declared using the pipe symbol to indicate that a variable may hold any of the constituent types defined in the set.”
Examples
simple
“The programmer used a union type to handle both strings and numbers.”
contextual
“When writing the function, she defined a union type so the input could be either a single user ID or an array of IDs.”
complex
“In TypeScript, a union type is declared using the pipe symbol to indicate that a variable may hold any of the constituent types defined in the set.”
Usage
Commonly used in computer science and statically-typed programming languages like C, C++, and TypeScript.
Etymology
A compound term formed from the mathematical concept of a union, denoting the set containing all elements of the given collections, and the computational sense of type. The nomenclature reflects the set-theoretic foundations of early programming language design.
Etymology adapted from Wiktionary, available under CC BY-SA 4.0.
Domain
Scan code
englishreference.com/q/union-type