Where to define typescript enum
Nuxt doesn't like any way I attempt to set up enums.
- If I put it in the file in /types/ with the interface, VS Code works great and seems to pick it up, but I get runtime error
Uncaught (in promise) ReferenceError: {enumName} is not defined
.
- I can export and import the enum only, but then my plugin and pages give me errors with Cannot find name {interfaceName}
in VS Code when I try to reference it.
- If I put the enum in it's own file, the interface can't find it. So I export the enum, and import it into the interface file, but the plugin and pages still give me errors with Cannot find name {interfaceName}
in VS Code when I try to reference it.
It seems like ./types was meant to contain interfaces only and no import export statements, or things break down.5 Replies
Workaround for now is to define the possible values on the interface instead of creating the enum.
Have you tried it with the global {} syntax?
I'll try that out
That doesn't seem to work either.
I mean a general advice is to not use typescript enums, since they can cause several issues, creating not only a "type" but also a "value". So if you can (and want to) I think it's best to migrate to union types https://fettblog.eu/tidy-typescript-avoid-enums/
If you don't want to, maybe there is another one here that has an idea of how to.
Ah, okay that's probably better. It's string values anyways, so a union type makes sense.