webxr icon indicating copy to clipboard operation
webxr copied to clipboard

Typescript definitions

Open NellWaliczek opened this issue 4 years ago • 12 comments

When I've been feeling up for it, I've puttering with using threejs in a typescript project of mine and noticed that the WebXR types haven't been added to the built in typescript definitions. I'm not super familiar with how this is done, but it looks like it might be with this tool?

https://github.com/microsoft/TSJS-lib-generator

Perhaps someone wants to do that?

NellWaliczek avatar Jan 21 '20 01:01 NellWaliczek

In case it's helpful, model-viewer uses Typescript, and I had updated its copy of types/webxr.ts as part of updating its WebXR support. That was fully manual, and only covered the parts of the API used by this application, so if there's a more automated way to generate the type mappings that would be strongly preferable. Is there a way to get this from IDL files directly?

klausw avatar Jan 21 '20 18:01 klausw

We at Babylon.js maintain a webxr.d.ts as well - https://github.com/BabylonJS/Babylon.js/blob/master/src/LibDeclarations/webxr.d.ts. I don't think there is a way to automate that process using a js or ts libs, as this is a native browser API and nothing we compile ourselves. Having said that, if the webxr polyfill is updated to the current specs, it is possible to generate declaration file(s) for the polyfill and use it as webxr.d.ts.

I will be happy to maintain the .d.ts file for webxr according to current specs

RaananW avatar Jan 24 '20 16:01 RaananW

add them at @types package https://www.npmjs.com/package/@types/npm but ideally, those should be part of immersive web package...

ManuelGraf avatar Mar 18 '20 13:03 ManuelGraf

I happen to have a reasonably up to date one I whipped up for the webxr implementation on noclip.website. I'll look into adding it to the registry. Not sure how out of date it is.

fordacious avatar Sep 22 '20 18:09 fordacious

We (babylonjs) will be distributing 4.2 with the following declaration file:

https://github.com/BabylonJS/Babylon.js/blob/master/src/LibDeclarations/webxr.d.ts

Does someone want to review it, or will it be helpful if I submit it somewhere (like @types/webxr)?

RaananW avatar Sep 29 '20 14:09 RaananW

@RaananW If you can create a repo for the package (to be published as @types/webxr) and transfer it to immersive-web that would be great! We can move forward from there.

I can do a more in depth review later, it looks mostly fine for now.

Manishearth avatar Sep 29 '20 18:09 Manishearth

@Manishearth - I am preparing the repository right now. It seems however, that the fastest (and safest) way to get the typings to @types is to submit it to [DefinitelyTyped] (https://github.com/DefinitelyTyped/DefinitelyTyped) (As explained here). I will submit a PR there once I am done with a bit of cleanup and documentation.

RaananW avatar Oct 07 '20 16:10 RaananW

That works, thanks!

Manishearth avatar Oct 07 '20 17:10 Manishearth

@RaananW please CC me when you make a PR, I would like to review some of the stuff there

Manishearth avatar Oct 09 '20 16:10 Manishearth

@Manishearth - of course. PR is coming Monday after i finished working on doc comments and a few cleanups.

RaananW avatar Oct 10 '20 05:10 RaananW

Is there anything to still be done here? It looks like the types were added a while ago and are pretty much up to date. https://www.npmjs.com/package/@types/webxr https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/webxr

msub2 avatar Sep 08 '21 00:09 msub2

The specs are constantly changing, there are a few things added and modified since the last update

RaananW avatar Sep 08 '21 11:09 RaananW