bytecodealliance / ComponentizeJS

JS -> WebAssembly Component
Apache License 2.0
242 stars 32 forks source link

enums not exported? #83

Open lwansbrough opened 9 months ago

lwansbrough commented 9 months ago

I'm getting the error source.js:2:43 SyntaxError: ambiguous indirect export: MyEnum when I try to import my enum like: import { MyEnum } from 'my_package:my_world/my_module' -- I see in debug mode that none of the enums appear to be exported.

guybedford commented 9 months ago

In JavaScript we don't export types currently - instead they are replicated by structure. So an enum is just a union of kebab case strings.

Introducing runtime type imports is tracking in https://github.com/bytecodealliance/jco/issues/235 and may be introduced in the future.

lwansbrough commented 9 months ago

Yeah I think it's important. I've got a ton of enums specified in wit files. Other guest code (ie. Rust) has access to them, so I think it makes sense that JS guest code would too. Otherwise the guest would have to replicate them so they can be passed as data. I'll keep an eye on the other issue, thanks.

guybedford commented 9 months ago

Right now it's easy enough to use them as just strings, but yes we are moving in the direction of runtime types.