Reference · pin this next to your editor

Reading TS syntax — the : / => decoder

Two worlds, two symbols. Find the world first; the meaning follows.

The two worlds

worldyou’re here when…survives runtime?
typeafter a : · inside type/interface · inside generic <…>no — erased
valueafter a = · being returned · passed as an argumentyes — real JS
Maxim: after : and before = = type. After = = value. (The type/interface keywords also put you in type world.)

The : — three jobs by position

positionmeaningexample
after a param nameparameter typef(x: string)
after the param list )return typef(): number
after a var / prop namethat var/prop’s typeconst u: User

The => — two jobs by world

worldmeaningright side is…
typefunction typethe return type
valuearrow functionthe body

Worked decodings

// 1) variable holding a function — type then value
const add: (a: number, b: number) => number = (a, b) => a + b;
//         └ type: a function type ┘            └ value: arrow fn ┘
//           (=> ⇒ return type number)            (=> ⇒ body a+b)

// 2) function declaration — return type rides after the : 
function greet(name: string): string { ... }
//                          ^ return type

// 3) pure type, erased
let make: () => { x: number };   // ⇒ compiles to:  let make;

// 4) interface method — the => is a TYPE (no body allowed)
interface Store { get: (id: string) => Item; }

The 3-second check

  1. After : / in type/interface/<…>? → type world; a => is a function type.
  2. After = / returned / passed as arg? → value world; a => is an arrow function.

Terminology (used interchangeably in the wild)

termmeans
type annotationthe explicit syntax you write after :
type informationany type the compiler knows — written or inferred
type definitiona named type you declare (type/interface) or a .d.ts declaration