gpt4 book ai didi

javascript - 在 "module"全局变量上运行 grunt-typescript 时,angular-mock 和 node.js 发生冲突

转载 作者:行者123 更新时间:2023-11-30 17:36:39 26 4
gpt4 key购买 nike

我正在使用 grunt-typescript,它正在编译我所有的 *.ts 文件。我同时使用了 angular-mocks.d.ts 和 node.d.ts,但是我在实际的 ts 文件中分别引用了它们。我仅将 angular-mocks 用于 jasmine 测试,并在我的 server.ts 文件中使用 Node 。
问题 我遇到的是,即使它们被单独引用,当它们在 grunt-typescript 中编译时,它似乎以某种方式将它们转储在一起,以便它们对“模块”的两个不同定义最终矛盾。如果我使用 tsc(引用 node.d.ts)自己构建我的 server.ts 文件,它构建得很好。这两者实际上永远不会重合,所以对我来说真的不是冲突,只是它在 grunt-typescript 中变成了冲突,它似乎在编译时将所有 *.d.ts 文件转储在一起。我认为这是因为它将我所有的 *.ts 文件构建在一起,因此最终将 *.d.ts 文件拉到一个公共(public)空间中。

我得到的错误:

c:/node/bills/typings/node/node.d.ts(37,13): error TS2134: Subsequent variable declarations must have the same type. Variable 'module' must be of type '(...modules: any[]) => any', but here has type '{ exports: any; require(id: string): any; id: string; filename: string; loaded: boolean; parent: any; children: any[]; }'.

angular-mocks.d.ts “模块”定义:

declare var module: (...modules: any[]) => any;

node.d.ts“模块”定义:

declare var module: {
exports: any;
require(id: string): any;
id: string;
filename: string;
loaded: boolean;
parent: any;
children: any[];
}

最佳答案

这最终对我有用。我将我的测试 .ts 文件拆分成一个单独的 typescript 运行。这导致它不能同时运行我的测试声明和我的运行时声明。将它们分开后,模块环境声明不再冲突。

    typescript: {
options:
{
target: 'es5', //or es3
base_path: '',
sourcemap: true,
declaration: false
},
server: {
src: ['*.ts']
},
test: {
src: ['test/*.ts']
}
},

watch: {
files: ['*.ts', 'test/*.ts'],
tasks: ['typescript:server', 'typescript:test']
}

关于javascript - 在 "module"全局变量上运行 grunt-typescript 时,angular-mock 和 node.js 发生冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21918067/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com