[英]How can I use the typescript definitions for both Gulp and RequireJS in the same project?
I have a Visual Studio 2015 ASP.Net Core project which uses Gulp and RequireJS. 我有一个使用Gulp和RequireJS的Visual Studio 2015 ASP.Net Core项目。 Gulp is used at compile-time, and RequireJS is used at run-time.
Gulp在编译时使用,而RequireJS在运行时使用。
The typescript definitions for Gulp include the definitions for node, and this causes a definition collision with RequireJS: Gulp的打字稿定义包括node的定义,这导致与RequireJS的定义冲突:
TS2403 Build:Subsequent variable declarations must have the same type. Variable 'require' must be of type 'NodeRequire', but here has type 'Require'.
Is there a way to work around this? 有办法解决这个问题吗?
I don't want to manually edit the definition files as that would create maintenance problems compared to just getting them directly from NPM. 我不想手动编辑定义文件,因为与直接从NPM获取文件相比,这会产生维护问题。
Also it wouldn't fully solve the problem as require
would have the wrong type in one of the situations depending on which I commented out. 同样,它也不能完全解决问题,因为根据我的评论,在一种情况下
require
的类型错误。
I found this question: Unable to use requireJS and Node's Require in the same TypeScript project . 我发现了这个问题: 无法在同一TypeScript项目中使用requireJS和Node的Require 。
It has an answer suggesting using CommonJS everywhere, but as I don't own the Gulp or RequireJS typings I can't change that. 它有一个建议在任何地方使用CommonJS的答案,但是由于我不拥有Gulp或RequireJS类型,因此无法更改它。
Hopefully you're using two tsconfig.jsons, one for compile-time concerns and one for run-time concerns. 希望您使用两个tsconfig.jsons,一个用于编译时关注,一个用于运行时关注。 With two configs you can explicitly choose which types to apply to each target with the
types
compiler option. 通过两个配置,您可以使用
types
编译器选项明确选择要应用于每个目标的types
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.