winjs/winjs — pull request #107 by xirzec (2014-04-11 18:14:38+00:00)
Title: Open for comment: Should we move WinJS sources to TypeScript?

I've had a lot of success using TypeScript on previous projects. I find that it saves you a lot of runtime debugging by catching silly errors early. It also makes refactoring much easier since you can do things in the IDE like "Find All References" and "Rename Symbol". As such, I wanted to see how difficult it would be to convert WinJS to using TypeScript so we can have a discussion about it.

This branch contains the start (though nowhere near the end) of moving to TypeScript. I made all of the files that contribute to base.js compile as TS files and I moved the files in the base directory to use TypeScripts modules and classes instead of WinJS.Namespace.define and WinJS.Class.define.

There is still a lot more work to do if we want to commit to TypeScript, such as putting type info into our all of functions and creating custom event types for the modules and classes that implement an event pattern. However, in the interest of transparency I didn't want to go too far down this road before opening the floor for discussion from the community.

Feel free to check out this branch and look around at the source. If you are just curious about what the generated JS will look like, I made some gists for convenience:

* [base.js before TypeScript] (https://gist.github.com/xirzec/78fb5755550dbf1a197b/d480e9416d366c82e4e660964bc5af080da336b4)
* [base.js after TypeScript] (https://gist.github.com/xirzec/78fb5755550dbf1a197b/e6cd3639067bdbcc93b7cda7d63b6465a864bd8c)
* [a diff between them] (https://gist.github.com/xirzec/78fb5755550dbf1a197b/revisions)

The diff algorithm gist uses isn't the best in some cases, so I recommend using an offline diff tool of your choice if you really want to scrutinize them closely. There are a few cases where comments and whitespace get lost. This is a known point in time issue of the TS compiler and will be addressed in later versions. It appears that the external doc-comments are all preserved.

TL;DR Should we move WinJS to TypeScript? :)