Skip to content

Conditionals ​

OperatorEffect
? :the only branching construct
??reacts only to null/undefined, not a general conditional

? : : the only branching construct ​

The condition must be a boolean; the result type is the union of both branches. Ternaries nest to express ladders — indentation is free-form.

typeflow
tier: user.points >= 100 ? "gold"
    : user.points >= 50 ? "silver"
    : "bronze"

?? : reacts only to null/undefined, not a general conditional ​

?? is not a general conditional — it only reacts to null/undefined, while ? : branches on any boolean.

typeflow
displayName: user.nickname ?? user.firstName
badge: user.verified ? "verified" : "unverified"

Playground ​

Mapping✔Playground ↗
Input JSON
Output
{
  "tier": "gold"
}
inferred type{ tier: "gold" | "standard" }

Note the inferred type of tier: "gold" | "standard", not just string.

Next: Arrays.

Released under the MIT License.