Skip to content

Instantly share code, notes, and snippets.

@Rafael09ED
Last active February 10, 2025 20:32
Show Gist options
  • Save Rafael09ED/ff9c706ec538b7ef74f42f1b33eab0bd to your computer and use it in GitHub Desktop.
Save Rafael09ED/ff9c706ec538b7ef74f42f1b33eab0bd to your computer and use it in GitHub Desktop.
let working = true;
const coffee = {
coffeeAmount: 10,
drink: () => { coffee.coffeeAmount -= 5; },
[Symbol.toPrimitive]() {
return coffee.coffeeAmount === 0 ? "empty" : coffee.coffeeAmount
},
refill: () => {
coffee.coffeeAmount += 5;
coffeePot.coffeePotAmount -= 5;
}
}
const work = {
execute: () => { },
}
const coffeePot = {
coffeePotAmount: 10,
brew: () => { coffeePot.coffeePotAmount = 10; },
[Symbol.toPrimitive]() {
return coffeePot.coffeePotAmount === 0 ? "empty" : coffeePot.coffeePotAmount
}
}
// code on the cup:
while (working) {
coffee.drink();
work.execute();
if (coffee == "empty") {
if (coffeePot == "empty")
coffeePot.brew();
coffee.refill();
}
}
@Rafael09ED
Copy link
Author

Rafael09ED commented Feb 10, 2025

Runs w/ npx tsx cup.ts but vscode gives:
LN 34 This comparison appears to be unintentional because the types '{ coffeeAmount: number; drink: () => void; [Symbol.toPrimitive](): number | "empty"; refill: () => void; }' and 'string' have no overlap.

LN 35 This comparison appears to be unintentional because the types '{ coffeePotAmount: number; brew: () => void; [Symbol.toPrimitive](): number | "empty"; }' and 'string' have no overlap..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment