Course contentsShow
← TypeScript
Lesson 1759 of 1,79640. The Future of TypeScriptFree lesson

Pipeline Operator and Type Flow

How the pipeline operator proposal would affect type inference through chained transformations.

Pipeline Operator and Type Flow

You'll learn how the proposed pipeline operator would enable TypeScript to infer types through a chain of transformations more naturally than today's nested function calls.


What Is the Pipeline Operator?

The pipeline operator (|>) is a TC39 proposal (currently Stage 2) that would let you write sequential transformations in a left-to-right flow instead of inside-out nesting:

// Today: nested calls (right-to-left reading)
const result = formatCurrency(calculateTax(applyDiscount(getPrice(item), 0.1), 0.08));

// With pipeline: linear flow (left-to-right)
const result = item
  |> getPrice(%)
  |> applyDiscount(%, 0.1)
  |> calculateTax(%, 0.08)
  |> formatCurrency(%);

The % represents the value flowing through the pipeline.


How Type Flow Would Work

TypeScript's type inference would follow the pipeline naturally:

  • The output type of each step becomes the input type of the next
  • Generics would flow through the chain automatically
  • Each % position would be typed as the previous step's return value

Think of it like a typed conveyor belt: each station knows exactly what shape the item has when it arrives, transforms it, and passes it forward with a new shape.


Why This Matters for Type Inference

Today's nested calls can confuse inference because TypeScript resolves them inside-out. The pipeline would make the data flow match the type flow, potentially improving:

  • Error localization: Pinpoint exactly which step breaks the chain
  • Autocomplete: Suggest methods available at each % position
  • Generic preservation: Less type widening through transformation chains
  • Readability: Types mirror the visual flow of data

Key Takeaway: The pipeline operator proposal would align TypeScript's type inference with the visual left-to-right flow of data transformations, making chained operations more intuitive to write and type-check.