Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does TypeScript pipe operator mean when used with strings?

I know about union types, but what does this pipe syntax mean?

let propName: "name" | "age" | "location";

Source: https://blogs.msdn.microsoft.com/typescript/2016/12/07/announcing-typescript-2-1/

like image 714
KarolDepka Avatar asked Jan 05 '17 01:01

KarolDepka


1 Answers

To answer my own question: those are "String Literal Types" as in https://www.typescriptlang.org/docs/handbook/advanced-types.html#string-literal-types

String literal types allow you to specify the exact value a string must have. In practice string literal types combine nicely with union types, type guards, and type aliases. You can use these features together to get enum-like behavior with strings.

like image 68
KarolDepka Avatar answered Oct 14 '22 09:10

KarolDepka