#Why does my switch statement not work?

1 messages · Page 1 of 1 (latest)

trail bough
#

Hey!
So i basically have a exported var of type Language (enum which contains DE_DE and EN_US) .
In my switch statement i use this variable and check against this (see below)

switch (language) {
        case Language.DE_DE: {
            console.log("German")
            return "Listet alle verfügbaren Befehle"
        }
        default: {
            console.log("Fallback to english")
            return "Lists all available commands"
        }
    }```
Somehow it always uses the default. Do i need to add breaks even though i return?
Here the variable:
```typescript
export var language = Language.DE_DE;```
scenic pebble
#

That doesn't tell us what Language.DE_DE is, a string? a number? an object?

trail bough
#
enum Language {
    DE_DE,
    EN_US
}```
nimble quarry
#

unrelated;

#

!:var

limpid vortexBOT
#
that_guy977#0
`!that_guy977:var`:

Don't use var in modern JS/TS applications! Its function scoping can lead to unexpected behavior. It is superceded by the block-scoped const and let. Read more

trail bough
#

hmm

#

its actually undefined

#

Should i not just import it like this?

import { language } from "../Bot";```
thorn pumice
#

`enum Language {
DE_DE = 'German',
EN_US = 'English'
}

console.log(Language.DE_DE);
`

#

Also if you return you should not nead to break in a switch case

nimble quarry
trail bough
#

yep

nimble quarry
#

your entry point imports stuff from everywhere else in your project

#

only scenario where you'd export stuff from the entry point is if you're building a library, and there you still wouldn't import from your entry point within your own library

#

that kind of thing creates circular dependancies

thorn pumice
trail bough
#

Changed it to now use the entry point any more and now it just works. Thanks!