Recently, I stumbled upon some code that introduces a class with specific variables defined in an unconventional manner.
export class Foo {
id: string = "A regular string"
bar: '>' | '<' | '=' | '<=' | '>=' = '>';
}
The variable 'bar' caught my attention as it deviates from the usual type definition style. Instead of specifying a type directly, it consists of a list of strings separated by pipes, followed by an assignment to one of these strings at the end.
My intuition suggests that this setup restricts the possible values for the variable 'bar' to those listed and eventually assigns the value '>'.
Is there a term or name associated with this unique declaration method? I couldn't find any information on it in the official documentation on variable declarations.