0 of 5 problems solved0%
3 of 5

Parse Boolish

Real-world inputs often encode booleans as strings or numbers. A Boolish union captures the allowed encodings, and narrowing with typeof and equality checks produces a real boolean. Be explicit about which spellings you accept and map each deterministically.

type Truthy = "yes" | "true" | 1 | true;

Keep branches small and clear so intent is obvious to readers and to the type checker.

Your Task

  • Create type Boolish = true | false | 'true' | 'false' | 'yes' | 'no' | 1 | 0.
  • Implement toBoolean(v: Boolish): boolean with this mapping:
  • true, 'true', 'yes', 1 → true
  • false, 'false', 'no', 0 → false.