Я получаю несколько ошибок Duplicate identifier
и Subsequent property declarations must have the same type.
при запуске yarn check-types
в моем проекте.
package. json:
{
"scripts": {
"start": "webpack-dev-server --mode development --hot",
"build": "webpack --mode production",
"check-types": "tsc"
},
"dependencies": {
"react": "^16.12.0",
"react-dom": "^16.12.0"
},
"devDependencies": {
"@babel/core": "^7.8.3",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/plugin-proposal-object-rest-spread": "^7.8.3",
"@babel/preset-env": "^7.8.3",
"@babel/preset-react": "^7.8.3",
"@babel/preset-typescript": "^7.8.3",
"@hot-loader/react-dom": "^16.11.0",
"@types/react": "^16.9.17",
"@types/react-dom": "^16.9.4",
"babel-loader": "^8.0.6",
"html-webpack-plugin": "^3.2.0",
"react-hot-loader": "^4.12.18",
"typescript": "^3.7.5",
"webpack": "^4.41.5",
"webpack-cli": "^3.3.10",
"webpack-dev-server": "^3.10.1"
}
}
tsconfig. json
{
"compilerOptions": {
"target": "ESNext",
"strictNullChecks": true,
"moduleResolution": "node",
"allowJs": true,
"noEmit": true,
"strict": true,
"esModuleInterop": true,
"jsx": "react",
"lib": [
"es2015",
"dom.iterable",
"es2016.array.include",
"es2017.object",
"dom"
],
"module": "es6",
"removeComments": true,
"alwaysStrict": true,
"allowUnreachableCode": false,
"noImplicitAny": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"forceConsistentCasingInFileNames": true,
"importHelpers": true
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
"dist"
]
}
пример ошибок:
node_modules/@types/react-native/globals.d.ts:40:15 - error TS2300: Duplicate identifier 'FormData'.
40 declare class FormData {
~~~~~~~~
node_modules/typescript/lib/lib.dom.d.ts:5710:11
5710 interface FormData {
~~~~~~~~
'FormData' was also declared here.
node_modules/typescript/lib/lib.dom.d.ts:5720:13
5720 declare var FormData: {
~~~~~~~~
and here.
node_modules/typescript/lib/lib.dom.iterable.d.ts:84:11
84 interface FormData {
~~~~~~~~
and here.
node_modules/@types/react-native/globals.d.ts:85:5 - error TS2717: Subsequent property declarations must have the same type. Property 'body' must be of type 'string | ArrayBuffer | ArrayBufferView | Blob | FormData | URLSearchParams | ReadableStream<Uint8Array> | null | undefined', but here has type 'string | ArrayBuffer | DataView | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | ... 8 more ... | undefined'.
85 body?: BodyInit_;
~~~~
node_modules/typescript/lib/lib.dom.d.ts:1553:5
1553 body?: BodyInit | null;
~~~~
'body' was also declared here.
node_modules/@types/react-native/globals.d.ts:111:14 - error TS2300: Duplicate identifier 'RequestInfo'.
111 declare type RequestInfo = Request | string;
~~~~~~~~~~~
node_modules/typescript/lib/lib.dom.d.ts:20034:6
20034 type RequestInfo = Request | string;
~~~~~~~~~~~
'RequestInfo' was also declared here.
node_modules/@types/react-native/globals.d.ts:130:13 - error TS2403: Subsequent variable declarations must have the same type. Variable 'Response' must be of type '{ new (body?: string | ArrayBuffer | ArrayBufferView | Blob | FormData | URLSearchParams | ReadableStream<Uint8Array> | null | undefined, init?: ResponseInit | undefined): Response; prototype: Response; error(): Response; redirect(url: string, status?: number | undefined): Response; }', but here has type '{ new (body?: string | ArrayBuffer | DataView | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | ... 8 more ... | undefined, init?: ResponseInit | undefined): Response; prototype: Response; error: () => Response; redirect: (url: string, status?: number | undefined) => Response; }'.
130 declare var Response: {
~~~~~~~~
node_modules/typescript/lib/lib.dom.d.ts:12875:13
12875 declare var Response: {
~~~~~~~~
'Response' was also declared here.
node_modules/@types/react-native/globals.d.ts:206: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>'.
206 abort: ProgressEvent;
~~~~~
node_modules/typescript/lib/lib.dom.d.ts:19004:5
19004 "abort": ProgressEvent<XMLHttpRequestEventTarget>;
~~~~~~~
'abort' was also declared here.
node_modules/@types/react-native/globals.d.ts:207: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>'.
207 error: ProgressEvent;
~~~~~
node_modules/typescript/lib/lib.dom.d.ts:19005:5
19005 "error": ProgressEvent<XMLHttpRequestEventTarget>;
~~~~~~~
'error' was also declared here.
node_modules/@types/react-native/globals.d.ts:208: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>'.
208 load: ProgressEvent;
~~~~
node_modules/typescript/lib/lib.dom.d.ts:19006:5
19006 "load": ProgressEvent<XMLHttpRequestEventTarget>;
~~~~~~
'load' was also declared here.
node_modules/@types/react-native/globals.d.ts:209: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>'.
209 loadend: ProgressEvent;
~~~~~~~
node_modules/typescript/lib/lib.dom.d.ts:19007:5
19007 "loadend": ProgressEvent<XMLHttpRequestEventTarget>;
~~~~~~~~~
'loadend' was also declared here.
node_modules/@types/react-native/globals.d.ts:210: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>'.
210 loadstart: ProgressEvent;
~~~~~~~~~
node_modules/typescript/lib/lib.dom.d.ts:19008:5
19008 "loadstart": ProgressEvent<XMLHttpRequestEventTarget>;
~~~~~~~~~~~
'loadstart' was also declared here.
node_modules/@types/react-native/globals.d.ts:211: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>'.
211 progress: ProgressEvent;
~~~~~~~~
node_modules/typescript/lib/lib.dom.d.ts:19009:5
19009 "progress": ProgressEvent<XMLHttpRequestEventTarget>;
~~~~~~~~~~
'progress' was also declared here.
node_modules/@types/react-native/globals.d.ts:212: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>'.
212 timeout: ProgressEvent;
~~~~~~~
node_modules/typescript/lib/lib.dom.d.ts:19010:5
19010 "timeout": ProgressEvent<XMLHttpRequestEventTarget>;
~~~~~~~~~
'timeout' was also declared here.
node_modules/@types/react-native/globals.d.ts:253:14 - error TS2300: Duplicate identifier 'XMLHttpRequestResponseType'.
253 declare type XMLHttpRequestResponseType = '' | 'arraybuffer' | 'blob' | 'document' | 'json' | 'text';
~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/typescript/lib/lib.dom.d.ts:20227:6
20227 type XMLHttpRequestResponseType = "" | "arraybuffer" | "blob" | "document" | "json" | "text";
~~~~~~~~~~~~~~~~~~~~~~~~~~
'XMLHttpRequestResponseType' was also declared here.
node_modules/@types/react-native/globals.d.ts:258:15 - error TS2300: Duplicate identifier 'URLSearchParams'.
258 declare class URLSearchParams {
~~~~~~~~~~~~~~~
node_modules/typescript/lib/lib.dom.d.ts:16123:11
16123 interface URLSearchParams {
~~~~~~~~~~~~~~~
'URLSearchParams' was also declared here.
node_modules/typescript/lib/lib.dom.d.ts:16156:13
16156 declare var URLSearchParams: {
~~~~~~~~~~~~~~~
and here.
node_modules/typescript/lib/lib.dom.iterable.d.ts:263:11
263 interface URLSearchParams {
~~~~~~~~~~~~~~~
and here.
node_modules/@types/react-native/globals.d.ts:291: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'.
Обратите внимание, что я рассмотрел решения для вопрос переполнения стека и включил include
и exclude
в tsconfig.json
, как предложено в наиболее голосуемом ответе. Но это не работает для меня.