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.

from documentation:

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

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -