Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add types for WebAssembly #1675

Closed
wants to merge 6 commits into from
Closed

Conversation

dsseng
Copy link
Contributor

@dsseng dsseng commented Feb 4, 2019

/cc @ry

@ry
Copy link
Member

ry commented Feb 4, 2019

@sh7dm Thanks.

@kitsonk I'm playing around with how to import the wasm types ... Do you have any suggestions?

Currently I get this:

> ./tools/build.py deno && ./target/debug/deno tests/wasm.js && ./target/debug/deno tests/wasm.ts
ninja: Entering directory `/Users/rld/src/deno/target/debug'
[1/1] Regenerating ninja files
[14/14] LINK ./deno
42
Compiling /Users/rld/src/deno/tests/wasm.ts
/Users/rld/src/deno/tests/wasm.ts:11:24 - error TS2304: Cannot find name 'WebAssembly'.

11 const wasmModule = new WebAssembly.Module(wasmCode);
                          ~~~~~~~~~~~
/Users/rld/src/deno/tests/wasm.ts:13:26 - error TS2304: Cannot find name 'WebAssembly'.

13 const wasmInstance = new WebAssembly.Instance(wasmModule, {});
                            ~~~~~~~~~~~

@kitsonk
Copy link
Contributor

kitsonk commented Feb 4, 2019

@ry I am not overly impressed with the Definitely Typed types. There are a few issues with them and how they vary from the spec.

Because of the way we generate the library, we only deal with types where we have functional code and depend upon a lib for everything else that is built in. So I would propose to add a lib specifically for web Assembly and prepend that to the runtime lib along side the esnext one. I have a branch where I am doing that. It will require a change to make the lib builder more flexible as well.

@ry
Copy link
Member

ry commented Feb 4, 2019

@kitsonk Ok sounds good.

Is declare namespace WebAssembly the way to go? Or is that what you mean by varying from the spec?

@kitsonk
Copy link
Contributor

kitsonk commented Feb 4, 2019

@ry

  1. It doesn't include the streaming addendum (https://webassembly.github.io/spec/web-api/)
  2. It doesn't include string literals where it should (in some of the descriptor)
  3. Some of the names don't align to the IDL
  4. It exposes properties on the errors
  5. It redefines BufferSource instead of using the global one
  6. It uses any in some instances where it should be using object

While my idea works, because the lib isn't included with the standard libs with TypeScript which means in editors, you will just get errors and the --types wouldn't work for most people. I am going to have to inline the file into the type library. Working on that now.

@ry
Copy link
Member

ry commented Feb 5, 2019

Closed in favor of #1677 - thanks for getting this started @sh7dm!

@ry ry closed this Feb 5, 2019
@dsseng dsseng deleted the add-wasm-types branch February 5, 2019 05:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants