vansimke / DojoTypeDescriptionGenerator

Application written in ASP.NET (C#) and TypeScript to read the dojo api (http://dojotoolkit.org/api) and generate initial TypeScript definition files
Apache License 2.0
3 stars 1 forks source link

Generated typescript definitions cannot be used from TypeScript natively #1

Closed jandic closed 9 years ago

jandic commented 9 years ago

Hello,

I tried to use the generated files available at DefinitelyTyped in TypeScript using native TypeScript programming but the modules cannot be imported. For example the following code does not work:

import lang = require("dojo/_base/lang");

It says that module does not exist even when I add reference. I had a look at how the definition file is created and I suspect it is due to nested module definitions. Would it be possible to modify the generator to generate correct module names similar to what is done here:

https://github.com/schungx/Dojo-TypeScript

Thanks.

vansimke commented 9 years ago

Hello,

I found the same issue when I started to try to integrate this into my first production project. Unfortunately, timing being what it was (and since no one had mentioned it...), I wasn't able to redesign the generator to make this change. My after-work schedule is lightening up a bit. Let me take a look and I'll try to get back to you in the next few days.

jandic commented 9 years ago

That would be great, thanks!

vansimke commented 9 years ago

Hey, I had some time tonight and updated the generator to add the module declarations. Can you try them again? Pull from my fork of DefinitelyTyped - I haven't submitted a PR to the main repo pending getting some more validation around these type defs. If things look good, let me know and I will close the issue.

jandic commented 9 years ago

Hi, it looks great. I just submitted a small pull request to the Generator fixing missing semicolons but apart from that, definitions work fine.

Also, I was wondering whether it would be worth to generate definition files for Dojo 1.10 rather than 1.9?

Thanks.

jandic commented 9 years ago

I also added some code to fix issues with keyword escaping so generated definition files are almost ready to be used (apart from dojox).

vansimke commented 9 years ago

I'd like too, but it is not trivial to do that since the generated type defs need a lot of massaging to workout inconsistencies in the API. If people start to use this, then I think I would want to submit a series of requests to the Dojo source to allow the generator to get a better initial load by cleaning up the comments that are used to generate the docs. Then it should only take a bit of hand polishing to bring it home. For now, I would probably create the 1.9 and 1.10 files with the generator and then take the diff into the github version and polish the diff only.

vansimke commented 9 years ago

I've contacted the Dojo core team and will start to work with them on updating the docs to support the code generator. For now, closing this issue.

sedwards2009 commented 9 years ago

Are the definitions files in a state right now where they can be tried out, or is the problem described in this issue still blocking this?

vansimke commented 9 years ago

tl;dr: yes.

Long answer: I am currently converting a Dojo-JavaScript application over to using the typings on my fork of Definitely Typed (here: https://github.com/vansimke/DefinitelyTyped). I am making changes every hour or so, but they are mostly minor adjustments to tune the type defs to how Dojo really works (sometimes the generator and/or API docs get it wrong :)).

vansimke commented 9 years ago

If you have any questions, let me know and I'll help you out. There are some tricks to getting the widgets working with the TypeScript classes. The readme in the dojo branch gives you a couple of scenarios, but I've changed how I'm building custom widgets. Haven't had a chance to update the readme yet.

sedwards2009 commented 9 years ago

Thanks for your reply. I didn't notice your fork there. I'll try out a few experiments with it when I find some time. I've got a sizable code base which uses Dojo and could use some help from TypeScript before it collapses under its own weight. I've read the readme and the story around dijits and subclasses looks like it needs some more investigation.

vansimke commented 9 years ago

I just got home from work and I have some time. I'll try to update the readme with an example of how I am using typescript. Will comment again when its up.

vansimke commented 9 years ago

Okay, I've updated the readme in my fork of DefinitelyTyped (https://github.com/vansimke/DefinitelyTyped/tree/master/dojo). Recomendations for improvements are encouraged. After I finish the conversion of my current project, I will submit a pull request to the main repo so that it can be integrated.

vansimke commented 9 years ago

Just wanted yo let you know that my latest type defs have been merged back into the main definitely typed repo. Might want to start using that one again, if you had switched to my fork. They took the whole thing en masse, so it reflects mine exactly right now.

sedwards2009 commented 9 years ago

Thanks for the info.

I'm doing some experiments to see if there is a better way to mix TS and Dojo classes. If it turns out to be interesting then I'll put it up on github.

sedwards2009 commented 9 years ago

I've gotten a slightly different approach working for the Dojo + TypeScript class problem. See https://github.com/sedwards2009/dojo-typescript-class