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 webassembly-js-api for *_bg.d.ts. #1312

Closed
wants to merge 1 commit into from
Closed

Add webassembly-js-api for *_bg.d.ts. #1312

wants to merge 1 commit into from

Conversation

konkers
Copy link

@konkers konkers commented Mar 5, 2019

Per #1040, import 'webassembly-js-api' is needed for WebAssembly.Memory.

Per #1040, `import 'webassembly-js-api'` is needed for `WebAssembly.Memory`.
@alexcrichton
Copy link
Contributor

Thanks for the PR!

This inspired me to write some tests we can run on CI to ensure that this doesn't regress. In making that though I'm wondering if this is necessary? There it looks like just depending on @types/webassembly-js-api is enough to pacity the TypeScript compiler, but I'm curious if perhaps there's a common way to use TypeScript or configure it which does require this? (I'm not too familiar with TypeScript myself)

@konkers
Copy link
Author

konkers commented Mar 5, 2019

Ooh Typescript tests. Nice.

So, I'm not super familiar with with TS either. I looked around a bit. Essentially you're asking the TS compiler to introduce something into the global scope automatically. As far as I can tell, that's not a common thing to do.

@alexcrichton
Copy link
Contributor

I agree yeah it's nonstandard and in general a bad idea, but for this case specifically WebAssembly is like String and Array where it's ambiently available in JS (part of the JS spec) and doesn't typically need an import. For that I think the import shouldn't be necessary because the JS types are already in scope and don't need imports

@Pauan
Copy link
Contributor

Pauan commented Mar 6, 2019

I have a lot of experience with TypeScript.

Yeah, this needs to be added to the TypeScript compiler. They already do that for ES6 + DOM APIs. That's the standard way that TypeScript handles globals.

They have a tracking issue here: microsoft/TypeScript#29747

@alexcrichton
Copy link
Contributor

Thanks for the reference and comment @Pauan! Sounds like we should close this for now but recommend depending on @types/webassembly-js-api in the meantim?

@Pauan
Copy link
Contributor

Pauan commented Mar 6, 2019

Yes, installing @types/webassembly-js-api should be enough for now (TypeScript automatically loads type definitions from the @types namespace).

If that issue takes too long to fix, we can gently ping the TypeScript team.

@alexcrichton
Copy link
Contributor

Sounds good to me!

@konkers would you be interested in perhaps sending a PR to update our documentation for using TypeScript to indicate this?

@konkers
Copy link
Author

konkers commented Mar 6, 2019

Odd! I though I tried with just@types/webassembly-js-api installed. Guess not. I reverted my patch and it's all working now. Thanks for the pointers @Pauan!

@konkers
Copy link
Author

konkers commented Mar 6, 2019

Yeah, I'll send a PR for a doc update.

@konkers
Copy link
Author

konkers commented Mar 6, 2019

I'm thinking that adding an example using typescript with callouts about @types/webassembly-js-api and the necessary webpack configs would be best. Thoughts?

@alexcrichton
Copy link
Contributor

@konkers an example sounds like a great idea to me!

@abau
Copy link

abau commented May 16, 2019

Yes, installing @types/webassembly-js-api should be enough for now

Just for the record, apparently one has to install @types/webassembly-js-api@0.0.3 since installing the latest version fails due to:

$ npm install --save @types/webassembly-js-api
npm WARN deprecated @types/webassembly-js-api@2.0.0: This is a stub types definition. webassembly-js-api provides its own type definitions, so you do not need this installed.
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/webassembly-js-api - Not found
npm ERR! 404 
npm ERR! 404  'webassembly-js-api@*' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404 It was specified as a dependency of '@types/webassembly-js-api'
npm ERR! 404 
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

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.

4 participants