bytecodealliance / ComponentizeJS

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

How to import types or records from imported interfaces? #38

Closed alisomay closed 1 year ago

alisomay commented 1 year ago

a.wit

package foo:a

interface foo {
   record bar {
      baz: string
   }
}

b.wit

Does not work with componentize.

package foo:b

world b {
   use foo:a/foo.{bar}

   export test: func() -> bar
}

Does not work with componentize.

package foo:b

world b {
   import foo:a/foo.{bar}

   export test: func() -> bar
}

Would work with componentize but then the type will not be recognized in wit

package foo:b

world b {
   import foo:a/foo

   export test: func() -> bar
}

On the js side I'd like to use it as

import { bar } from "foo:a/foo"

If bar was a func then I can use it as above.

I couldn't yet find a way to import types from interfaces.

Basically the ideal form for me would be,

package foo:b

world b {
   use foo:a/foo.{bar}

   export test: func() -> bar
}

which works with no issues when writing the component in Rust with wit-bindgen.

I'd be grateful if you could point me to the right direction. 🙏

guybedford commented 1 year ago

Thanks for posting, agreed we should support these cases, marking as a bug, and I'll aim to pick it up soon.

guybedford commented 1 year ago

I've landed the fix for this in https://github.com/bytecodealliance/componentize-js/commit/5e68ce33f2fe5f6056ce00a20757fee6159acdff, going out in the next release later today or tomorrow. But if there's anything I've missed please do post back. Thanks for the issue!

alisomay commented 1 year ago

Great to hear! I'll give it a try in the upcoming days. Thank, you.