4

我已经玩了几个小时打字稿了,还没有弄清楚我是如何将淘汰赛与我的模块一起导入的?

如果没有打字稿,我将需要它define(["require", "exports", "knockout" ...],function(... , ko),但我还没有设法让打字稿生成它。

我不知道从 jquery 到淘汰赛有什么区别,$ 工作正常,但 ko 未定义。

///<reference path="../knockoutd.d.ts" />
///<reference path="../jquery.d.ts" />
import dl = module("DataLayer");
import vm1 = module("AppBarViewModel");
import vm2 = module("Nav2ViewModelCommander");
import vm3 = module("IdentityViewModel");
export class AppViewModel {
...
}

结果是 :

    define(["require", "exports", "DataLayer", "AppBarViewModel", "Nav2ViewModelCommander",  "IdentityViewModel"], function(require, exports, __dl__, __vm1__, __vm2__, __vm3__) {
    var dl = __dl__;

    var vm1 = __vm1__;

    var vm2 = __vm2__;

    var vm3 = __vm3__;

更新

///<amd-dependency path="knockout" />

define(["require", "exports", "DataLayer", "AppBarViewModel", "Nav2ViewModelCommander", "IdentityViewModel", "knockout"], function(require, exports, __dl__, __vm1__, __vm2__, __vm3__) {
    var dl = __dl__;

    var vm1 = __vm1__;

    var vm2 = __vm2__;

    var vm3 = __vm3__;
4

4 回答 4

2

To make the compiler include AMD dependencies in your resulting JavaScript without importing them in your TypeScript, you can make use of this code:

/// <amd-dependency path="path/to/knockout/js" />

This feature is badly documented, but oh-so-useful.

于 2013-04-08T09:41:57.730 回答
1

The problem is that KnockoutJS doesn't define window.ko in an AMD environment (i.e. when RequireJS is involved). Therefore you either have to use ///<amd-dependency /> or use KnockoutJS as a proper module.

I have drafted up an AMD version of knockout.d.ts from DefinitelyTyped - it will allow you to use import ko = module('knockout'). Make sure you obtain both knockout.d.ts and knockout.amd.d.ts.

于 2013-05-22T00:42:15.317 回答
1

With latest typescript and type definition for knockout.d.ts

import ko = require('knockout')

works as expected.

于 2013-10-23T13:39:08.397 回答
0

添加以下内容:

import ko= module("knockout");

更新

情况1:

根据您的错误,这似乎更合理module can not be aliased to a none module type您的 knockout.ts 文件不包含模块定义。要使用模块指令导入文件文件,应该在该文件中定义一个模块。

案例2

In case this is not working it is most likely due to this : https://stackoverflow.com/a/13013956/390330 You should give the path to knockout.d.ts file :

import ko= module("/path/to/knockout.d.ts");

However I think it should not be required since you are referencing a .ts file and not a .d.ts file :

///<reference path="knockout.ts" />
于 2013-04-08T00:14:36.183 回答