Skip to content

Comparisons & logic ​

OperatorEffect
== != < <= > >=compare two values, produce a boolean
&&logical AND — both operands must be boolean
[`
!boolean negation

== != < <= > >= : compare two values, produce a boolean ​

Comparing values whose types have no overlap — a number against a string, say — can never be true. The compiler warns (TF2367) instead of letting the mapping silently return false forever. Remove the mismatched literal to fix it — it is a warning, not an error, so the mapping still runs.

typeflow
isAdult: user.age >= 18
isAdmin: user.role == "admin"
passed: user.score > 50

&& : logical AND — both operands must be boolean ​

&&, ||, and ! require boolean operands — no truthiness on strings or numbers. user.active && user.age is rejected (TF2004) since age is not boolean.

typeflow
canPost: user.active && user.verified

|| : logical OR — both operands must be boolean ​

typeflow
needsReview: !user.verified || user.age < 16

! : boolean negation ​

typeflow
blocked: !user.verified

Playground ​

Mapping✔Playground ↗
Input JSON
Output
{
  "canPost": false,
  "needsReview": true
}
inferred type{ canPost: boolean; needsReview: boolean }

Next: Conditionals.

Released under the MIT License.