/// import { cell, recipe, UI } from "commontools"; // Tests nullish coalescing (??) interaction with && and || // ?? should NOT be transformed to when/unless (different semantics) export default recipe("LogicalNullishCoalescing", (_state) => { const config = cell<{ timeout: number | null; retries: number | undefined }>({ timeout: null, retries: undefined, }); const items = cell([]); return { [UI]: (
{/* ?? followed by || - different semantics */} Timeout: {(config.get().timeout ?? 30) || "disabled"} {/* ?? followed by && */} {(config.get().retries ?? 3) > 0 && "Will retry"} {/* Mixed: ?? with && and || */} {items.get().length > 0 && (items.get()[0] ?? "empty") || "no items"}
), }; });