Union
Noun · Development
Definitions
In type systems, a union type represents a value that can be one of several types — written as `string | number` in TypeScript, meaning the value is either a string or a number. In C/C++, a `union` is a memory construct where multiple fields share the same memory location, so only one field is valid at a time, used for memory-efficient variant storage.
In plain English: A type that says a value could be one of several different types — like a field that might contain either text or a number.
Example: "The API returns `string | null`, so TypeScript forces you to handle the null case before you can call string methods on it."