UNPKG

functionalscript

Version:

FunctionalScript is a purely functional subset of JavaScript

54 lines (53 loc) 1.54 kB
import { asBase, asNominal } from "./module.f.js"; export default { pre: () => { const strA = asNominal(7560413859n); // "¢£" const strB = asNominal(7560413860n); // "¢¤" if (strA === strB) { throw [strA, strB]; } // // TypeScript compilation error. // const x1 = strA > strB // { const a = { value: 1 }; const b = { value: 2 }; // No Compile-time error if (a < b) { } } { const x = { _brand: 'NoCompare' }; // No Error if (x < x) { } } { const a = {}; const b = {}; // No Error a < b; } { const a = undefined; const b = undefined; // a < b; // TS2469: Operator '<' cannot be applied to type 'symbol'. } }, nominal: () => { const userIdA = asNominal(123); const userIdB = asNominal(456); if (userIdA === userIdB) { throw [userIdA, userIdB]; } const to = asBase; const to2 = asBase; const userId2A = asNominal(123); const userId2B = asNominal(456); if (userId2A === userId2B) { throw [userId2A, userId2B]; } // if (userIdA === userId2A) { throw [userIdA, userId2A] } // compilation error const n1 = to(userIdA); const n2 = to2(userId2A); // const x = to(userId2A) // compilation error } };