typescript - 忽略一个项目中的定义,但不忽略另一个
问题描述
我有一个带有node_modules
文件夹的工作区和一个src
包含我的客户端和服务器打字稿代码的文件夹。它看起来像这样:
/node_modules
/@types
/node
/requirejs
/src
/client
/admin
/index.ts
/tsconfig.json
/public
/index.ts
/tsconfig.json
/server
/index.ts
/tsconfig.json
我正在使用requirejs
我的客户端代码和node
我的服务器代码。他们每个人都有相似的类型,所以当我构建我的代码时,我得到以下错误:
node_modules/@types/node/index.d.ts(6860,5): error TS2300: Duplicate identifier 'mod'.
node_modules/@types/requirejs/index.d.ts(38,11): error TS2300: Duplicate identifier 'mod'.
node_modules/@types/requirejs/index.d.ts(422,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'require' must be of type 'NodeRequire', but here has type 'Require'.
有没有办法让我的客户端代码忽略node
定义,让我的服务器代码忽略requirejs
定义?
解决方案
由于客户端和服务器构建具有单独tsconfig.json
的文件,因此您只需设置types
编译器选项以限制node_modules/@types
在每个构建中自动加载的包。或者,您可以为两个构建设置单独node_modules
的目录。如果您无法使其正常工作,请在您的问题中添加更多信息,我会再看一遍。
推荐阅读
- python - 错误:找不到满足要求的版本 tensorflow==2.1.0 和 No matching distribution found for tensorflow==2.1.0
- powershell - 将存档 zip 文件解压缩到与存档 zip 文件同名的文件夹中
- realm - keycloak API 出现 403 错误
- angular - 当 JSON 字段名称中有空格时,将来自 Web 服务的 JSON 响应映射到 Angular 类
- javascript - 在反应本机导航屏幕之间切换时,PanGesture 动画不起作用
- reactjs - 将 CRA 捆绑到单个 js 文件中
- python - Pyspark:为什么 ST_intersects 函数返回重复的行?
- c# - 在 Swashbuckle 5 中显示模型内部 IFormFile 的上传按钮
- ios - ios swift中注销后如何调用appdelegate.swift?
- java - 我们可以在 for 循环中定义未知数量的具有不同输出的可点击文本吗?