2

To develop a Windows Store Application, how to use WinJS.Class.define() to define a class in Typescript?

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.