1

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 the WebWorker lib, but it conflicts with DOM lib and produces an 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.

Oleg Valter
  • 6,098
  • 6
  • 22
  • 37

1 Answers1

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.

Matt McCutchen
  • 22,711
  • 1
  • 39
  • 54
  • Thanks for your comment, Matt, I read through the documents and tried to implement your suggestion. I had some problems, but felt like the problem belongs its own individual post, https://stackoverflow.com/q/52437384/6683308 (I am pretty new to asking questions on the internet, please let me know if I should somehow combine this two posts) but thank you for your input – Shunxu Huang Sep 21 '18 at 05:55