2

我使用最新版本在 VS2012 中创建了一个项目并添加了两个文件

// file x.ts
export class test {}

// file search.ts
import t = module('x');

问题 - 如何修复以下错误:

Error   1   ';' expected.   D:\Code\Search\Search\node_modules\search\search.ts   1 18  search.ts
Error   2   Module cannot be aliased to a non-module type.  D:\Code\Search\Search\node_modules\search\search.ts 1   1   search.ts
Error   3   Unable to resolve module reference 'module'.    D:\Code\Search\Search\node_modules\search\search.ts 1   12  search.ts

csproj 包含以下内容:

<TypeScriptCompile Include="node_modules\search\x.ts" />
<TypeScriptCompile Include="node_modules\search\search.ts" />
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
    <TypeScriptTarget>ES5</TypeScriptTarget>
    <TypeScriptRemoveComments>false</TypeScriptRemoveComments>
    <TypeScriptSourceMap>true</TypeScriptSourceMap>
    <TypeScriptModuleKind>AMD</TypeScriptModuleKind>
</PropertyGroup>
<Import Project="$(VSToolsPath)\TypeScript\Microsoft.TypeScript.targets" />

x.ts 编译得很好,但 search.ts 不是

define(["require", "exports"], function(require, exports) {
    var test = (function () {
    function test() {
    }
    return test;
})();
exports.test = test;
});
//# sourceMappingURL=x.js.map
4

1 回答 1

3

如果您使用的是最新版本,我假设您的意思是0.9.1?在这种情况下,您不能module再将关键字用于外部模块的导入语句,而是使用require

// file search.ts
import t = require('x');

另一个问题可能是由于 search.ts 找不到 x.ts 造成的,如果上述方法不能解决您的问题,请发布您的文件夹结构。

于 2013-08-30T12:39:37.777 回答