Logical Types
Edit pageLast modified: 02 February 2025The TypeLang, like PHP, supports two types of composite (logical) types: Union and Intersection. The ability to specify a nullable type using a separate expression is also supported.
Union Types
Each union type is separated by a pipe character (|
) and may contain any other type definition.
tip
A | B | C
Intersection Types
Each intersection type is separated by an ampersand character (&
) and may contain any other type definition.
tip
A & B & C
Nullable Types
Nullable type is a shortened alias for union type T | null
and is written as ?T.
Examples
Counterexamples
tip
Description of nullable type
Example
(equivalent toExample | null
)?Example
warning
The question mark must be placed before the type name.
Example?
An error similar to the one below should occur
ParseException: Syntax error, unexpected "?"
Parentheses
Parentheses can be used to disambiguate types.
tip
Disjunctive form (DNF).
(A & B) | C
tip
Conjunctive form (CNF).
(A | B) & C