如果您知道如何解决问题,请改为发出拉取请求。
@types/xxxx
包但遇到了问题。Definitions by:
中的index.d.ts
)以便他们可以回复.使用 v9.6.6,我的 Angular 项目一切正常。 升级到 10.0.0,现在我在运行单元测试时遇到以下错误:
Error: node_modules/@types/node/index.d.ts(2381,15): error TS2300: Duplicate identifier 'URL'.
node_modules/@types/node/index.d.ts(2399,15): error TS2300: Duplicate identifier 'URLSearchParams'.
node_modules/@types/node/index.d.ts(2417,14): error TS2661: Cannot export 'URL'. Only local declarations can be exported from a module.
node_modules/@types/node/index.d.ts(2417,19): error TS2661: Cannot export 'URLSearchParams'. Only local declarations can be exported from a module.
node_modules/typescript/lib/lib.dom.d.ts(12210,11): error TS2300: Duplicate identifier 'URL'.
node_modules/typescript/lib/lib.dom.d.ts(12226,13): error TS2300: Duplicate identifier 'URL'.
node_modules/typescript/lib/lib.dom.d.ts(14282,11): error TS2300: Duplicate identifier 'URLSearchParams'.
node_modules/typescript/lib/lib.dom.d.ts(14309,13): error TS2300: Duplicate identifier 'URLSearchParams'.
我正要记录同样的问题!
我试过这个:
npm init
npm i -g typescript
npm i --save-dev @types/node
tsc --init
touch index.ts
tsc
我得到这些相同的错误。
添加对最新作者的额外提及:@rbuckton。
我也在看这个。 最后一次推送以同样的错误破坏了我们的构建。
也得到这个。 在我的情况下,看起来与 Typescript 有冲突。
通过降级到 v9.6.7 修复它
是的。 在OP的帖子中,冲突与lib.dom.d.ts
。 我还看到lib.d.ts
和lib.es2017.full.d.ts
冲突。
是的。 也看到了这一点。
也遇到过这个问题,通过将@types/node
降级到 v9.6.7 修复
我们仍在使用最新的 LTS (8),因此我们(暂时)通过使用^8.0.0
解决了这个问题。
我今晚就能看这个了。
您可以通过@dependabot了解这一重大变化的影响
可能大多数 TS 用户都包含@types/node
,这导致了重复的标识符和失败的 CI 。
@rbuckton感谢您对此进行调查👍
快速解决:
npm i @types/[email protected]
对于使用 nodejs v6.xx 的老式家伙 - npm i --save-dev @types/node@6
这是因为这些类被更改为全局导出,当前文件中的第 2380 行。 请参阅下面的历史比较:
https://github.com/DefinitelyTyped/DefinitelyTyped/commit/bffb03282272b37ccb12429026f4504a39a3cd83#diff -7d84e08967cded0b99ed4328aab0a1a8
我正要拉动并进行更改,但看起来@rbuckton在此过程中已经领先于我。
@robertbradleyux在节点 10.0.0 中, URL 类也可用于全局对象,因此这似乎是正确的。
@rbuckton有没有办法告诉 TypeScript 只定义尚未定义的类?
在这种情况下,节点和浏览器都实现了相同的 WHATWG URL 标准,因此这类似于setTimeout
在 Node.js 中具有与浏览器不同的返回类型https://nodejs.org/dist/latest -v10.x/docs/api/timers.html
不知何故,TypeScript 能够处理setTimeout
所以它肯定可以处理全局 URL,对吗?
更新我看到已经有一个拉取请求来恢复这个更改https://github.com/DefinitelyTyped/DefinitelyTyped/pull/25356
清除我的 npm 缓存后,我仍然收到原始错误
@kgorlick在类型发布者将更新的类型发布到 npm 之前,这不会显示。
@styfle 、 toJSON()
不在 DOM 版本中,而 DOM 版本有一个静态的createObjectURL
方法没有出现在 NodeJS 版本中)。
我临时解决了添加的问题
"lib": ["es6"],
在我的 tsconfig.json 中
@rbuckton我知道他们在URL
定义中可能存在一些差异。
setTimeout
在 Node.js 中的返回类型与浏览器不同: docs
然而不知何故,包括@types/node
不会破坏构建。 那一个如何工作?
IIRC,定时器 API 的多个版本成为重载。 URL 的问题在于它是一种对象类型。
在@11.9.3
上遇到此错误并通过以下方式修复:
npm i @types/[email protected] --save-dev
收到此错误
与 "@types/node": "^11.9.4",
node_modules/@types/node/index.d.ts:75:15 - 错误 TS2300:重复标识符“SharedArrayBuffer”。
75 声明类 SharedArrayBuffer {
~~~~
node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts:24:11
24 接口 SharedArrayBuffer {
~~~~
此处还声明了“SharedArrayBuffer”。
node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts:46:13
46 声明 var SharedArrayBuffer: SharedArrayBufferConstructor;
~~~~
和这里。
node_modules/@types/node/index.d.ts:83:15 - 错误 TS2451:无法重新声明块范围变量“自定义”。
等等.....
@Mulperi我认为您的问题与上述不同,并且与 #32878 中将interface SharedArrayBuffer
更改class SharedArrayBuffer
。
@SimonSchick我认为这应该改回来,因为它实际上只是一个前向声明。
@Flarna这仅在您加载 dom 类型时才有效,节点类型应该在不加载 dom 类型的情况下工作..
它不是dom
而是es2017.sharedmemory
,它通过/// <reference lib="es2018" />
包含在 3.1 类型中,但较旧的打字稿版本不支持reference lib
指令。
前向声明用于避免每个人都必须手动包含它的需要。 前向声明应为interface
因为接口与类合并,而类不允许被定义两次。 因此,使用class
进行前向声明会破坏包含具有实际定义的 lib 的构建。
在这种情况下, @Flarna会简单地将/// <reference lib="es2017.sharedmemory" />
到/index.d.ts
中吗?
也很重要,因为这些类型中仍然缺少Atomics
🤔
不,因为/// <reference lib
已在打字稿 3.0 中引入,受影响的文件是用于 2.1...3.0 的文件。
@Mulperi您使用哪个打字稿版本? 我希望它 <3.1。
我也遇到这个问题。 并更改为@types/node
的先前版本不是一个可行的选择,因为@types/connect
使用*
,拉动@^11.9
,并导致测试套件中的冲突。
@Flarna我目前正在旅行,你能不能看看这个?
@jmeberlein您使用哪个打字稿版本? 我希望它 <3.1。
创建 #33177。 很难判断这个 get 何时合并,因为 CI 当前处于不良状态。
package.json 中的 Typescript 版本 ^2.9.2,在 npm-shrinkwrap.json 中解析为 2.9.2
为什么这个故事被关闭了? 好像还是断了。
为什么这个故事被关闭了? 好像还是断了。
这几乎是一年前解决的,所以它似乎已经修复,但现在已经倒退。 我可能会开一个新问题。
ng] ERROR in node_modules/@types/node/index.d.ts:73:11 - error TS2300: Duplicate identifier 'IteratorResult'.
[ng] 73 interface IteratorResult<T> { }
[ng] ~~~~~~~~~~~~~~
[ng] node_modules/typescript/lib/lib.es2015.iterable.d.ts:41:6
[ng] 41 type IteratorResult<T, TReturn = any> = IteratorYieldResult<T> | IteratorReturnResult<TReturn>;
[ng] ~~~~~~~~~~~~~~
[ng] 'IteratorResult' was also declared here.
[ng] node_modules/typescript/lib/lib.es2015.iterable.d.ts:41:6 - error TS2300: Duplicate identifier 'IteratorResult'.
[ng] 41 type IteratorResult<T, TReturn = any> = IteratorYieldResult<T> | IteratorReturnResult<TReturn>;
[ng] ~~~~~~~~~~~~~~
[ng] node_modules/@types/node/index.d.ts:73:11
[ng] 73 interface IteratorResult<T> { }
[ng] ~~~~~~~~~~~~~~
[ng] 'IteratorResult' was also declared here.
问题仍未解决
@thameurr请注意,您对很久以前关闭的问题发表了评论。 我假设您使用的是一组不同的 @types/node、typescript、... 版本,然后是本期中提到的版本。
您能否创建一个新问题,说明如何在使用最新版本的软件包的地方进行复制?
我用@types/node: "13.9.5"
遇到了这个问题,它通过回滚到"12.12.31"
解决了🤷♂️
Type error: Duplicate identifier 'ProcessEnv'
这个问题在我使用 TypeScript 4.0.2 时仍然发生。 在14.6.0
版本安装@types/node
似乎使运行tsc --noEmit
时错误消失。
最有用的评论
我今晚就能看这个了。