Last active
February 10, 2025 20:32
-
-
Save Rafael09ED/ff9c706ec538b7ef74f42f1b33eab0bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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..