TypeScript with KnockoutJS

CallumVass picture CallumVass · Oct 2, 2012 · Viewed 51.1k times · Source

Is there any sample of using TypeScript with KnockoutJS? I'm just curious as to how they would work together?

Edit

Here is what I have, seems to work

declare var ko: any;
declare var $: any;
class ViewModel {
    x = ko.observable(10);
    y = ko.observable(10);

}

$(() => {
    ko.applyBindings(new ViewModel());
});

This generates into the following Javascript:

var ViewModel = (function () {
    function ViewModel() {
        this.x = ko.observable(10);
        this.y = ko.observable(10);
    }
    return ViewModel;
})();
$(function () {
    ko.applyBindings(new ViewModel());
});

Answer

George Mavritsakis picture George Mavritsakis · Oct 26, 2012

Look at DefinitelyTyped.

"TypeScript type definitions repository for popular JavaScript libraries"