-
Notifications
You must be signed in to change notification settings - Fork 261
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
Typescript definitions #50
Comments
I'd love to take a look. I haven't dived into typescript yet. I'm curious how much verbose it makes things for stuff like |
Nothing happend? I haven't used yet twgl, but I would, if there were typescript definitions for it. |
@colorpump : I'm still working on this. Twgl is a huge library, if you use all the sub modules. |
@mode777 It seems to me actually almost complete. Maybe I can help. In your file I found declare module "twgl.js" {
// ...
// draw module
export module draw {
export function drawBufferInfo(gl: WebGLRenderingContext, bufferInfo: BufferInfo | VertexArrayInfo, type?: number, count?: number, offset?: number): void;
export function drawObjectList(objectsToDraw: DrawObject[]): void;
}
export function drawBufferInfo(gl: WebGLRenderingContext, bufferInfo: BufferInfo | VertexArrayInfo, type?: number, count?: number, offset?: number): void;
export function drawObjectList(objectsToDraw: DrawObject[]): void;
|
@greggman back to mode777's original question 😉 ... Is it fine for you that he contributes the types to GitHub: DefinitelyTyped or would you like to do it as the owner of twgl.js? Sorry for pushing so much 😄 ... I just think it would be a huge enhancement for twgl.js. @mode777 I just don't really understand your point about 'owning' the repositories. Wouldn't you just fork DefinitelyTyped like 10 thousand others and make a pull request, and in the end it's part of |
@colorpump Not sure if I understand your question, but consuming the submodules will work just like in javascript:
EDIT Sorry, now I get it: The redundancy here comes from twgl.js and is on purpose. That's why it is included twice. @greggman: My opinion on this has changed. I think the definition files should be contributed together with the library in the same npm package. This seems to be the way many libraries are doing it (rxJS, electron, Angular...). If you agree, I will fork twgl.js add the definitions and submit a pull request. |
I haven't used TypeScript yet. Looking forward to it! Do one of you guys mind forking twgl, adding in the typescript stuff, and setting up whatever other files are needed so I can see it work and compile? In other words I want to be able to, load up a typescript based example in VSCode, see VSCode show the typescript completions for twgl, see a twgl example written in typescript, see it process the sample into JavaScript so I can run it. I don't know what the best way to do that is. In a subfolder? Stuff in the root? In a separate project? If any of you have time to do that it would be really helpful. I'd basically like to see a working example so I have something to go off of. |
As mode777 took the initiative and also did already a lot, I want to let him go first. @mode777 if you are busy these days, and want me to do it, it would be no problem for me - on the contrary: I would like to be helpful. My idea would be:
I don't think it's necesarry to have a typescript loader included. But if you think different, we have to ....
I think it would be easier for people who are interested to install typescript globally and run on the personal computer: What do you guys think? |
@colorpump This seems like a reasonable way to go. Ideally you would run I'm actually quite busy at the moment, so if you want to finish the definitions (I just used the excellent documentation for it) it would be highly appreciated. @greggman I understand, that you want to see it work in action. I can set up a demo once the definitions are complete. Even plain Javascript users could benefit from the definitions, as many IDEs like vscode can use them to enchance dev experience. |
Yes, of course. I start tomorrow. |
I do not see the twgl.d.ts file anywhere. |
@sami-badawi Currently it's only in my fork repo under the branch feature-typescript-support. I realized that the twgl functions and Type Definitions are constantly under development. So I'm trying to work on an automatic test, in order to keep the definitions file in sync with the library itself. I'll keep you updated here. |
Thanks @colorpump |
I would place your definition file in a source folder and reference it by ///<reference path="./pathToYour/twgl.d.ts"/>
import * as twgl from 'twgl.js';
To avoid a reference tag in every module, I think you can use the "files" property in tsconfig.json. But you could also wait, until I'm done and until hopefully it's part of twgl.js. Then you will not need anything besides |
Thanks @colorpump. I followed your advice and added code.
I am building with Webpack and got a compile error.
I changed the my code to:
And still got same compile error.
Any ideas? |
Thanks @colorpump, my type definition is working fine, but I get a compile error when I call my build command:
When I installed the type definition file in Are you using Webpack too? |
yes, I tried the same example with webpack, and it did compile without errors. I used webpack 2.4.1 But now I would say: You found a dirty solution. This should be enough until twgl.js comes with typescript definition. Once it's included, you won't have problems. |
…rom this page https://gist.github.com/mode777/4f8eb25b123b2c5627034f797834f949 Tried to use more elegant approach suggested by @colorpump here: greggman/twgl.js#50 This code can be backed out when type definitions are added to twgl.js
I use Webpack 2.6, so I doubt that is the problem. I found a slightly better solution. Instead of having the type definition live here:
And I have a npm task:
If anybody else run into a similar problem before the twgl.js type definition gets rolled out, my code is here: |
I tried your type definition. I don't want it inside the
to
, removed the lines
and added
to |
Any progress on this? |
sorry, I'm out, as I got other projects. I wanted to write automated tests for the definition file, so that tests would bark when new updates in the core are done without updating the definition file. But that was a bigger pain as I expected. I hope someone can implement this feature. Otherwise I hope to find some time for it again this year - but I cannot promise. |
FWIW, I am using the typings from @sami-badawi , with some tweaks. I added a couple of functions, and corrected the https://github.com/geon/mem/commits/master/src/types/twgl.js/index.d.ts |
I uploaded a new PR (just as an example). It's got @pineapplemachine 's PR in it. It also has a typescript example started. I don't know typescript at all and I don't feel like digging around trying to figure out how to get VSCode to see the type file when editing the example so I just pushed it here and maybe someone else more familiar with typescript can upload a working version. What I want to happenLoad What it does nowHovering over Buildingdownload the PR then
Then, if you change something about how
To compile the .ts example
The sample HTML file is in Other issuestypescript by default has no knowledge of WebGL2 so loading |
Took @pineapplemachine 's latest and push a new PR here It builds and generates a .js file for the example, things seem to be typed in VSCode but the code doesn't run in the browser. It gets the error
Searching online it's not entirely clear to me if I have to use webpack/babel/rollup to get it to work or what. Will look into it if/when I have time unless someone else knows how to fix it. |
pushed 4.8.0 with .ts files |
I updated the dependency version and it's working great with my TS project that prompted me to come and talk about definitions in the first place. Heck yeah. I will certainly fix any errors that I come across, and if you @ me in any issues created by other devs in regards to the definitions I can take a look at them too. |
There's still the whole |
I wrote some typescript definitions for twgl, for a personal project. They don't cover the sub-modules yet, but I would be willing to add them.
However, I don't know how (if at all) to contribute them. I could just create a separate repo and publish them to definitely-typed and "@ types/twgl.js" on npm but I feel like these repos/packages shouldn't be owned by me.
Any suggestions?
The text was updated successfully, but these errors were encountered: