Val*_*rov 5 amd visual-studio requirejs typescript
我在打字稿+ requirejs上遇到了一些麻烦。我有两个项目(主要的一个和带有单元测试的一个)。看起来像这样:
moduleA.ts:
export class A {
constructor(someThing: string) {
this.someThing = someThing;
}
someThing: string;
}
export var aInst = new A("hello from module A");
Run Code Online (Sandbox Code Playgroud)
moduleB.ts:
import moduleA = require('moduleA');
export class B {
private a: moduleA.A;
constructor(a: moduleA.A) {
this.a = a;
}
getSomeThing() {
return this.a.someThing;
}
}
export var bInst = new B(moduleA.aInst);
Run Code Online (Sandbox Code Playgroud)
requireConfig.js:
require.config({
baseUrl: "/app",
});
Run Code Online (Sandbox Code Playgroud)
myTest.ts:
import moduleB = require('moduleB');
QUnit.test('my test', () => {
QUnit.equal("hello from module A", moduleB.bInst.getSomeThing());
});
Run Code Online (Sandbox Code Playgroud)
testRequreConfig.js:
require.config({
baseUrl: "../Base/app",
});
Run Code Online (Sandbox Code Playgroud)
index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="Content/qunit.css" type="text/css" />
<script type="text/javascript" src="Scripts/qunit.js"></script>
<script src="Scripts/require.js"></script>
<script src="test/testRequreConfig.js"></script>
</head>
<body>
<h1 id="qunit-header">Unit Tests</h1>
<h2 id="qunit-banner"></h2>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">test markup, will be hidden</div>
<script type="text/javascript">
(function () {
QUnit.config.autostart = false;
require(['test/myTest.js'], QUnit.start);
}());
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我们无法更改基础项目。我们希望能够在测试项目中使用moduleB(通过'moduleB'字符串按requirejs加载)。我们有什么:
TypeScript编译器无法解析外部模块(因为它不知道在哪里寻找它)。如果我们把
declare module "moduleB" {
export ...
}
Run Code Online (Sandbox Code Playgroud)
在* .d.ts文件中-那么我们将可以使用它。但是在实际项目中,我们有很多打字稿文件,并且不可能为每个文件手动编写“声明”。有什么办法可以解决吗?主要问题是事实,由于某些原因,我们无法编辑require.config。
是否有可能使tsc.exe知道require.config?
| 归档时间: |
|
| 查看次数: |
1979 次 |
| 最近记录: |