To develop a Windows Store Application, how to use WinJS.Class.define() to define a class in Typescript?
2 Answers
There is an MSDN article on TypeScript and WinJS that covers the basics.
To use TypeScript with WinJS you need to include the WinJS typings, which are on Codeplex.
This will give you auto-completion and type checking for your calls to WinJS library features.
Comments
You don't need to use WinJS.Class if you use TypeScript. Just create a normal class e.g:
class Foo{
bar = 123;
doBar(){
return this.bar;
}
}
For other things inside WinJS you can use these TypeScript definitions : https://github.com/borisyankov/DefinitelyTyped/blob/master/winjs/winjs.d.ts
1 Comment
Jeremy Foster
Agreed. In case the original poster was strictly wanting an actual WinJS.Class, the answer is that you cannot use TypeScript to do that. Your options are to use a TypeScript class as @basarat has suggested, or to just type WinJS.Class.define(...) as you would in standard JavaScript. Either should work fine, but using a TypeScript class is the better option from a readability standpoint.