Like sorting mail by type — in the "letters" pile, you know each item is a letter.
typeof value === "string" tells TypeScript that inside the if block, value is string, not number. TypeScript calls this narrowing.
> padStart("hello", 8) → " hello" (string branch)
> padStart(42, 5) → " 42" (number branch)Like sorting mail by type — in the "letters" pile, you know each item is a letter.
typeof value === "string" tells TypeScript that inside the if block, value is string, not number. TypeScript calls this narrowing.
> padStart("hello", 8) → " hello" (string branch)
> padStart(42, 5) → " 42" (number branch)Sign in to cast your vote
Sign in to share your feedback and join the discussion.