首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >用自定义库响应本机+类型记录:重复标识符错误

用自定义库响应本机+类型记录:重复标识符错误
EN

Stack Overflow用户
提问于 2021-11-25 13:03:10
回答 1查看 1.4K关注 0票数 1

我已经创建了一个自定义库,其中包含了我的所有API请求,以便在各种中使用。库在其package.json中有以下依赖项

代码语言:javascript
运行
复制
"dependencies": {
   "@types/node-fetch": "^2.5.10",
   "typescript": "^4.3.5"
}

它还包括一个用tsc构建库的postinstall脚本,因为这是一个类型记录项目。

在我的中,我已经通过它的GitHub存储库安装了这个库,并且当我的postinstall脚本运行时,我会得到以下“重复标识符”错误:

代码语言:javascript
运行
复制
npm ERR! command sh -c tsc
npm ERR! ../@types/node/globals.d.ts(47,11): error TS2300: Duplicate identifier 'AbortController'.
npm ERR! ../@types/node/globals.d.ts(60,11): error TS2300: Duplicate identifier 'AbortSignal'.
npm ERR! ../@types/node/globals.d.ts(67,13): error TS2300: Duplicate identifier 'AbortController'.
npm ERR! ../@types/node/globals.d.ts(72,13): error TS2300: Duplicate identifier 'AbortSignal'.
npm ERR! ../@types/react-native/globals.d.ts(49,13): error TS2403: Subsequent variable declarations must have the same type.  Variable 'Blob' must be of type '{ new (blobParts?: BlobPart[] | undefined, options?: BlobPropertyBag | undefined): Blob; prototype: Blob; }', but here has type '{ new (blobParts?: (string | Blob)[] | undefined, options?: BlobOptions | undefined): Blob; prototype: Blob; }'.
npm ERR! ../@types/react-native/globals.d.ts(54,15): error TS2300: Duplicate identifier 'FormData'.
npm ERR! ../@types/react-native/globals.d.ts(110,5): error TS2717: Subsequent property declarations must have the same type.  Property 'body' must be of type 'BodyInit | null | undefined', but here has type 'BodyInit_ | undefined'.
npm ERR! ../@types/react-native/globals.d.ts(118,5): error TS2717: Subsequent property declarations must have the same type.  Property 'window' must be of type 'null | undefined', but here has type 'any'.
npm ERR! ../@types/react-native/globals.d.ts(119,5): error TS2717: Subsequent property declarations must have the same type.  Property 'signal' must be of type 'AbortSignal | null | undefined', but here has type 'AbortSignal | undefined'.
npm ERR! ../@types/react-native/globals.d.ts(137,14): error TS2300: Duplicate identifier 'RequestInfo'.
npm ERR! ../@types/react-native/globals.d.ts(156,13): error TS2403: Subsequent variable declarations must have the same type.  Variable 'Response' must be of type '{ new (body?: BodyInit | null | undefined, init?: ResponseInit | undefined): Response; prototype: Response; error(): Response; redirect(url: string | URL, status?: number | undefined): Response; }', but here has type '{ new (body?: BodyInit_ | undefined, init?: ResponseInit | undefined): Response; prototype: Response; error: () => Response; redirect: (url: string, status?: number | undefined) => Response; }'.
npm ERR! ../@types/react-native/globals.d.ts(233,5): error TS2717: Subsequent property declarations must have the same type.  Property 'abort' must be of type 'ProgressEvent<XMLHttpRequestEventTarget>', but here has type 'ProgressEvent<EventTarget>'.
npm ERR! ../@types/react-native/globals.d.ts(234,5): error TS2717: Subsequent property declarations must have the same type.  Property 'error' must be of type 'ProgressEvent<XMLHttpRequestEventTarget>', but here has type 'ProgressEvent<EventTarget>'.
npm ERR! ../@types/react-native/globals.d.ts(235,5): error TS2717: Subsequent property declarations must have the same type.  Property 'load' must be of type 'ProgressEvent<XMLHttpRequestEventTarget>', but here has type 'ProgressEvent<EventTarget>'.
npm ERR! ../@types/react-native/globals.d.ts(236,5): error TS2717: Subsequent property declarations must have the same type.  Property 'loadend' must be of type 'ProgressEvent<XMLHttpRequestEventTarget>', but here has type 'ProgressEvent<EventTarget>'.
npm ERR! ../@types/react-native/globals.d.ts(237,5): error TS2717: Subsequent property declarations must have the same type.  Property 'loadstart' must be of type 'ProgressEvent<XMLHttpRequestEventTarget>', but here has type 'ProgressEvent<EventTarget>'.
npm ERR! ../@types/react-native/globals.d.ts(238,5): error TS2717: Subsequent property declarations must have the same type.  Property 'progress' must be of type 'ProgressEvent<XMLHttpRequestEventTarget>', but here has type 'ProgressEvent<EventTarget>'.
npm ERR! ../@types/react-native/globals.d.ts(239,5): error TS2717: Subsequent property declarations must have the same type.  Property 'timeout' must be of type 'ProgressEvent<XMLHttpRequestEventTarget>', but here has type 'ProgressEvent<EventTarget>'.
npm ERR! ../@types/react-native/globals.d.ts(280,14): error TS2300: Duplicate identifier 'XMLHttpRequestResponseType'.
npm ERR! ../@types/react-native/globals.d.ts(287,15): error TS2300: Duplicate identifier 'URL'.
npm ERR! ../@types/react-native/globals.d.ts(312,15): error TS2300: Duplicate identifier 'URLSearchParams'.
npm ERR! ../@types/react-native/globals.d.ts(356,5): error TS2717: Subsequent property declarations must have the same type.  Property 'onopen' must be of type '((this: WebSocket, ev: Event) => any) | null', but here has type '(() => void) | null'.
npm ERR! ../@types/react-native/globals.d.ts(357,5): error TS2717: Subsequent property declarations must have the same type.  Property 'onmessage' must be of type '((this: WebSocket, ev: MessageEvent<any>) => any) | null', but here has type '((event: WebSocketMessageEvent) => void) | null'.
npm ERR! ../@types/react-native/globals.d.ts(358,5): error TS2717: Subsequent property declarations must have the same type.  Property 'onerror' must be of type '((this: WebSocket, ev: Event) => any) | null', but here has type '((event: WebSocketErrorEvent) => void) | null'.
npm ERR! ../@types/react-native/globals.d.ts(359,5): error TS2717: Subsequent property declarations must have the same type.  Property 'onclose' must be of type '((this: WebSocket, ev: CloseEvent) => any) | null', but here has type '((event: WebSocketCloseEvent) => void) | null'.
npm ERR! ../@types/react-native/globals.d.ts(360,5): error TS2717: Subsequent property declarations must have the same type.  Property 'addEventListener' must be of type '{ <K extends keyof WebSocketEventMap>(type: K, listener: (this: WebSocket, ev: WebSocketEventMap[K]) => any, options?: boolean | AddEventListenerOptions | undefined): void; (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | ... 1 more ... | undefined): void; }', but here has type 'WebsocketEventListener'.
npm ERR! ../@types/react-native/globals.d.ts(361,5): error TS2717: Subsequent property declarations must have the same type.  Property 'removeEventListener' must be of type '{ <K extends keyof WebSocketEventMap>(type: K, listener: (this: WebSocket, ev: WebSocketEventMap[K]) => any, options?: boolean | EventListenerOptions | undefined): void; (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | ... 1 more ... | undefined): void; }', but here has type 'WebsocketEventListener'.
npm ERR! ../@types/react-native/globals.d.ts(364,13): error TS2403: Subsequent variable declarations must have the same type.  Variable 'WebSocket' must be of type '{ new (url: string | URL, protocols?: string | string[] | undefined): WebSocket; prototype: WebSocket; readonly CLOSED: number; readonly CLOSING: number; readonly CONNECTING: number; readonly OPEN: number; }', but here has type '{ new (uri: string, protocols?: string | string[] | null | undefined, options?: { [optionName: string]: any; headers: { [headerName: string]: string; }; } | null | undefined): WebSocket; ... 4 more ...; readonly OPEN: number; }'.
npm ERR! ../@types/react-native/globals.d.ts(388,15): error TS2300: Duplicate identifier 'AbortSignal'.
npm ERR! ../@types/react-native/globals.d.ts(388,15): error TS2420: Class 'AbortSignal' incorrectly implements interface 'EventTarget'.
npm ERR!   Property 'dispatchEvent' is missing in type 'AbortSignal' but required in type 'EventTarget'.
npm ERR! ../@types/react-native/globals.d.ts(411,15): error TS2300: Duplicate identifier 'AbortController'.
npm ERR! ../@types/react-native/globals.d.ts(436,14): error TS2717: Subsequent property declarations must have the same type.  Property 'error' must be of type 'DOMException | null', but here has type 'Error | null'.
npm ERR! ../@types/react-native/globals.d.ts(444,14): error TS2717: Subsequent property declarations must have the same type.  Property 'result' must be of type 'string | ArrayBuffer | null', but here has type 'string | ArrayBuffer'.
npm ERR! ../@types/react-test-renderer/node_modules/@types/react/index.d.ts(3065,14): error TS2300: Duplicate identifier 'LibraryManagedAttributes'.
npm ERR! ../@types/react-test-renderer/node_modules/@types/react/index.d.ts(3078,13): error TS2717: Subsequent property declarations must have the same type.  Property 'a' must be of type 'DetailedHTMLProps<AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>', but here has type 'DetailedHTMLProps<AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>'.
npm ERR! ../@types/react-test-renderer/node_modules/@types/react/index.d.ts(3079,13): error TS2717: Subsequent property declarations must have the same type.  Property 'abbr' must be of type 'DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>', but here has type 'DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>'.
...
npm ERR! ../@types/react-test-renderer/node_modules/@types/react/index.d.ts(3254,13): error TS2717: Subsequent property declarations must have the same type.  Property 'use' must be of type 'SVGProps<SVGUseElement>', but here has type 'SVGProps<SVGUseElement>'.
npm ERR! ../@types/react-test-renderer/node_modules/@types/react/index.d.ts(3255,13): error TS2717: Subsequent property declarations must have the same type.  Property 'view' must be of type 'SVGProps<SVGViewElement>', but here has type 'SVGProps<SVGViewElement>'.
npm ERR! ../@types/react/index.d.ts(3068,14): error TS2300: Duplicate identifier 'LibraryManagedAttributes'.
npm ERR! node_modules/typescript/lib/lib.dom.d.ts(1866,11): error TS2300: Duplicate identifier 'AbortController'.
npm ERR! node_modules/typescript/lib/lib.dom.d.ts(1873,13): error TS2300: Duplicate identifier 'AbortController'.
npm ERR! node_modules/typescript/lib/lib.dom.d.ts(1883,11): error TS2300: Duplicate identifier 'AbortSignal'.
npm ERR! node_modules/typescript/lib/lib.dom.d.ts(1893,13): error TS2300: Duplicate identifier 'AbortSignal'.
npm ERR! node_modules/typescript/lib/lib.dom.d.ts(5199,11): error TS2300: Duplicate identifier 'FormData'.
npm ERR! node_modules/typescript/lib/lib.dom.d.ts(5209,13): error TS2300: Duplicate identifier 'FormData'.
npm ERR! node_modules/typescript/lib/lib.dom.d.ts(13848,11): error TS2300: Duplicate identifier 'URL'.
npm ERR! node_modules/typescript/lib/lib.dom.d.ts(13865,13): error TS2300: Duplicate identifier 'URL'.
npm ERR! node_modules/typescript/lib/lib.dom.d.ts(13875,11): error TS2300: Duplicate identifier 'URLSearchParams'.
npm ERR! node_modules/typescript/lib/lib.dom.d.ts(13894,13): error TS2300: Duplicate identifier 'URLSearchParams'.
npm ERR! node_modules/typescript/lib/lib.dom.d.ts(17639,6): error TS2300: Duplicate identifier 'RequestInfo'.
npm ERR! node_modules/typescript/lib/lib.dom.d.ts(17791,6): error TS2300: Duplicate identifier 'XMLHttpRequestResponseType'.
npm ERR! src/services/HttpService.ts(15,31): error TS7006: Parameter 'value' implicitly has an 'any' type.
npm ERR! src/services/HttpService.ts(15,38): error TS7006: Parameter 'name' implicitly has an 'any' type.

我认为这是因为我已经将node-fetchtypescript类型安装在我的库中以及React中,但是我不知道如何解决这个问题。

可能有帮助的信息:我也有一个有角度的项目,我成功地安装了这个库。因此,它必须与反应本地项目有一定的关系。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-11-30 19:44:39

解决方案是在库的"postinstall": "tsc"中用"prepare": "tsc"替换package.json。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70111609

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档