简体   繁体   English

如何在同一项目中为Gulp和RequireJS使用打字稿定义?

[英]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? 有办法解决这个问题吗?

Manually Editing the Definitions 手动编辑定义

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的类型错误。

Relevant SO Questions 相关SO问题

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.

相关问题 如何使用柯南为 Visual Studio IDE 提供依赖项并创建同一项目的 package,再次使用柯南依赖项? - How can I use Conan to both provide dependencies for the Visual Studio IDE and create a package of the same project, again using Conan dependencies? 如何使用Node JS Tools在Visual Studio中调试Yeoman生成器KO(带有typescript和gulp)Node JS项目 - How can I debug a Yeoman generator KO (with typescript and gulp) Node JS project in Visual studio with Node JS Tools for visual studio 如何在VS 2015中使用TypeScript定义 - How to use TypeScript definitions in VS 2015 如何同时为.Net 3.5 和 4 编译一个项目 - How do I compile a project for both .Net 3.5 and 4 at the same time 如何使用libman而不是npm来下载typescript定义 - How to use libman instead of npm to download typescript definitions 如何在Visual Studio项目中集成Java和Python? - How can I integrate both Java and Python in a Visual Studio project? 如何使用单个 Visual Studio 解决方案同时构建 x86 和 x64? - How can I use a single Visual Studio solution to build both x86 and x64 at the same time? 我可以在不制作DLL的情况下使用同一项目中的UserControl吗? - Can I use a UserControl from the same project without making a DLL? typescript + reactjs + requirejs:如何将react-dom导入Typescript - typescript+reactjs+ requirejs: how to import react-dom into typescript 如何在许多Visual Studio(2013)项目中处理TypeScript类型定义? - How do I handle TypeScript type definitions across many Visual Studio (2013) projects?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM