How to avoid conflict between “dom” and “webworker” libs?

ぃ、小莉子 提交于 2019-12-23 05:29:16

问题


I am using TypeScript with React, and one of the things I want to achieve is background sync for offline support.

To enable typings for service worker, I have to include lib "webworker," but it conflicts with lib "dom." and produce such error:

(25,1): Definitions of the following identifiers conflict with those in another file: 
EventListenerOrEventListenerObject, BlobPart, HeadersInit, BodyInit,
RequestInfo, DOMHighResTimeStamp, PerformanceEntryList, PushMessageDataInit,
VibratePattern, BufferSource, DOMTimeStamp, FormDataEntryValue, 
IDBValidKey, MessageEventSource, BinaryType, ClientTypes, 
IDBCursorDirection, IDBRequestReadyState, IDBTransactionMode, 
NotificationDirection, NotificationPermission, PushEncryptionKeyName, 
PushPermissionState, ReferrerPolicy, RequestCache, RequestCredentials, 
RequestDestination, RequestMode, RequestRedirect, ResponseType, 
ServiceWorkerState, ServiceWorkerUpdateViaCache, VisibilityState, 
WorkerType, XMLHttpRequestResponseType

So I am wondering if there is any workaround except for typing most of my arguments any

Thanks :-)


回答1:


You can split your project into multiple parts with separate tsconfig.json files: one part that includes the dom lib and one part that includes the webworker lib. You can make another part for common code that doesn't depend on either library. You can use project references to help automate the build. If this doesn't fully solve the problem, please update the question to describe the outstanding issues.



来源:https://stackoverflow.com/questions/52377916/how-to-avoid-conflict-between-dom-and-webworker-libs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!