带有 KnockoutJS 的打字稿 [英] TypeScript with KnockoutJS

查看:30
本文介绍了带有 KnockoutJS 的打字稿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有将 TypeScript 与 KnockoutJS 结合使用的示例?我只是好奇他们将如何合作?

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

这是我所拥有的,似乎有效

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());
});

这会生成以下 Javascript:

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());
});

推荐答案

查看 DefinitelyTyped.

流行 JavaScript 库的 TypeScript 类型定义存储库"

"TypeScript type definitions repository for popular JavaScript libraries"

这篇关于带有 KnockoutJS 的打字稿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆