I've created a custom library that contains all my API-Requests to use in various React Native projects. The library has the following dependencies in its package.json
"dependencies": {"@types/node-fetch": "^2.5.10","typescript": "^4.3.5"}
It also includes a postinstall script to build the library with tsc
, since this is a Typescript project.
In my React Native project, I've installed the library through its GitHub repository and when my postinstall script is run, I get the following "Duplicate identifier" errors:
npm ERR! command sh -c tscnpm 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.
I think this is because I have installed the types of node-fetch
and typescript
in my library as well as in the React Native project, but I don't know how to fix this problem.
Information that might help: I also have an Angular project in which I successfully installed the library. So it must have something to do with the React Native project in particular.