typescript - Type definition with bar '|' operator -
i came across typescript code below:
export type statuscode = 'a1' | 'b2' | 'c3'; let code: statuscode = "c3";
what bar operator '|' here? have similar feature in javascript?
while can guess should similar enum
wanted know name of topic, can search , learn it.
the pipe operator used in typescript either create union types, type aliases or, you're looking for, string literal types. latter string enum. you're determining values string can have.
string literal types allow specify exact value string must have. in practice string literal types combine nicely union types, type guards, , type aliases. can use these features enum-like behavior strings.
Comments
Post a Comment