TypeScript 管道运算符与字符串一起使用时意味着什么?

What does TypeScript pipe operator mean when used with strings?

我知道联合类型,但是这个管道语法是什么意思?

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

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

回答我自己的问题:这些是 "String Literal Types",如 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.

我们称之为管道运算符。 实验性管道运算符 |>(目前处于第 1 阶段)允许以可读的方式创建链式函数调用。基本上,管道运算符在具有单个参数的函数调用上提供语法糖,允许您编写

'%21' |> decodeURI 而不是 decodeURI('%21').

例如:它是这样工作的