TypeScript,RequireJS和自定义RequireJS模块路径

时间:2015-08-20 10:05:07

标签: visual-studio requirejs typescript

我在VS2015中使用TypeScript,并尝试在其他模块中导入淘汰赛模块。 Knockout安装在" / knockout"以外的路径上,事实上,我所有的"库"安装到" / app / lib"。由于文件夹名称不一定与模块名称匹配,我在main.ts中定义了以下内容:

requirejs.config({
    baseUrl: "/app",
    paths: {
        "text"       : "lib/requirejs-text/text",
        "durandal"   : "lib/durandal/js",
        "plugins"    : "lib/durandal/js/plugins",
        "transitions": "lib/durandal/js/transitions",
        "knockout"   : "lib/knockout.js/knockout",
        "jquery"     : "lib/jquery/jquery",
        "bootstrap"  : "lib/bootstrap-sass-official/javascript/bootstrap"
    }
});

因此我的应用程序在运行时只能使用var ko = require("knockout")找到淘汰赛。

然而,在视觉工作室的设计时,我得到一个红色的波浪形"在我的require()电话下:

enter image description here

我相信这是因为VS试图使用路径而不是我的自定义路径配置来寻找Knockout。那么,我可以告诉VS我的自定义路径配置,这样可行吗?目前生成的JavaScript是:

var receiveDeliveryViewModel = (function () {
    function receiveDeliveryViewModel() {
        this.deliveryReference = ("");
    }
    return receiveDeliveryViewModel;
})();

您可以看到哪些内容并未引用Knockout.js。

非常感谢提前。

1 个答案:

答案 0 :(得分:1)

您需要为Knockout添加type definition

这将为Knockout提供类型信息,并解决您看到的导入错误。

也可通过NuGet获得(其他包经理可用)!

相关问题