Closed
Description
🔎 Search Terms
"switch(true)" case object type
🕗 Version & Regression Information
- This is a crash
- This changed between versions ______ and _______
- This changed in commit or PR _______
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about
switch
and{}
- I was unable to test this on prior versions because _______
⏯ Playground Link
💻 Code
const obj = {}
const str = 'abc'
switch (true) {
// @ts-expect-error
case obj: // No good, this is not an error.
// @ts-expect-error
case str: // OK, this is an error.
}
🙁 Actual behavior
When a case is an object ({}
) variable, the type-check passes. true
!== {}
so it will never execute.
🙂 Expected behavior
The type-check fails on the always false true === {}
comparison.
Additional information about the issue
This appeared to be distinct from: