Typescript 定义HeadersInit值时,工作盒路由中出现类型错误

Typescript 定义HeadersInit值时,工作盒路由中出现类型错误,typescript,workbox,Typescript,Workbox,我目前正在尝试使用TypeScript和WorkBox创建一个服务工作者。下面是我当前的工作盒定义(只是为了让它运行起来)。如何解决我解释的类型错误 在registerRoutepiece类型脚本编译器中,告诉matchPrecache需要两个参数,另一个是类型HeadersInit。如果未给出,则假定默认的内容类型:text/html。我希望显式地给出类型,但是当我这样做时,我得到一个错误,matchPrecache返回值是不可赋值的 如果我查一下,看起来是这样的 /** * A short

我目前正在尝试使用TypeScript和WorkBox创建一个服务工作者。下面是我当前的工作盒定义(只是为了让它运行起来)。如何解决我解释的类型错误

registerRoute
piece类型脚本编译器中,告诉
matchPrecache
需要两个参数,另一个是类型
HeadersInit
。如果未给出,则假定默认的
内容类型:text/html
。我希望显式地给出类型,但是当我这样做时,我得到一个错误,
matchPrecache
返回值是不可赋值的

如果我查一下,看起来是这样的

/**
 * A shortcut to create a strategy that could be dropped-in to Workbox's router.
 *
 * On browsers that do not support constructing new `ReadableStream`s, this
 * strategy will automatically wait for all the `sourceFunctions` to complete,
 * and create a final response that concatenates their values together.
 *
 * @param {Array<function({event, request, url, params})>} sourceFunctions
 * An array of functions similar to {@link module:workbox-routing~handlerCallback}
 * but that instead return a {@link module:workbox-streams.StreamSource} (or a
 * Promise which resolves to one).
 * @param {HeadersInit} [headersInit] If there's no `Content-Type` specified,
 * `'text/html'` will be used by default.
 * @return {module:workbox-routing~handlerCallback}
 * @memberof module:workbox-streams
 */
declare function strategy(sourceFunctions: StreamsHandlerCallback[], headersInit: HeadersInit): RouteHandlerCallback;
export { strategy };

编辑:好的!当我不只是查看VS代码错误,而是尝试构建时,我在命令行中发现了许多其他错误。一长段文字

node_modules/typescript/lib/lib.dom.d.ts:25:1 - error TS6200: Definitions of the following
identifiers conflict with those in another file: EventListenerOrEventListenerObject,
ImportExportKind, TableKind, ValueType, 
ExportValue, Exports, ImportValue, ModuleImports, 
Imports, name, ==> HeadersInit <==, BodyInit, RequestInfo, BlobPart, DOMHighResTimeStamp, CanvasImageSource, OffscreenRenderingContext, MessageEventSource, 
ImageBitmapSource, OnErrorEventHandler, TimerHandler, PerformanceEntryList, ReadableStreamReadResult, VibratePattern, AlgorithmIdentifier, HashAlgorithmIdentifier, BigInteger, NamedCurve,
 GLenum, GLboolean, GLbitfield, GLint, GLsizei, GLintptr, GLsizeiptr, GLuint, GLfloat, GLclampf, TexImageSource, Float32List, Int32List, GLint64, GLuint64, Uint32List, BufferSource, DOMTimeStamp, 
FormDataEntryValue, IDBValidKey, Transferable, BinaryType, CanvasDirection, CanvasFillRule, CanvasLineCap, CanvasLineJoin, CanvasTextAlign, CanvasTextBaseline, ClientTypes, ColorSpaceConversion, EndingType, IDBCursorDirection, IDBRequestReadyState, IDBTransactionMode, ImageOrientation, ImageSmoothingQuality, KeyFormat, KeyType, KeyUsage, NotificationDirection, NotificationPermission, OffscreenRenderingContextId, PermissionName, PermissionState, PremultiplyAlpha, PushEncryptionKeyName, PushPermissionState, ReferrerPolicy, RequestCache, RequestCredentials, RequestDestination, RequestMode, RequestRedirect, ResizeQuality, ResponseType, ServiceWorkerState, ServiceWorkerUpdateViaCache, VisibilityState, WebGLPowerPreference, WorkerType, XMLHttpRequestResponseType
在我的
package.json中

"@types/workbox-sw": "^4.3.1",
"@types/workbox-window": "^4.3.3",
所以也许这和这个有关


编辑2:只有在我将
//
位于文件顶部。删除它后,我会遇到与中所述相同的问题(就错误消息而言)


edit3:我删除了显式引用,找到并尝试将此库添加到
tsconfig.json
中,现在又出现了很多关于
dom
webworker
库定义之间类型冲突的消息



edit4:我注意到了类型脚本
dom
webworker
库冲突。从
tsconfig.json中删除
webworker
似乎无法解决
streamssstrategy
HeadersInit
的原始问题。请尝试为您的服务人员创建单独的文件夹,并为此文件夹扩展主tsconfig.json。 为此,您需要在serviceworker.ts文件夹中创建另一个tsconfig.json,其中包含以下内容:

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "noEmit": false
  },
  "lib": ["webworker"],
  "include": ["."]
}
而且,我希望,你们知道,服务人员必须像webworker一样编译成单独的文件。
您可以提供项目的链接吗?

尝试为您的服务人员创建单独的文件夹,并扩展此文件夹的main tsconfig.json。 为此,您需要在serviceworker.ts文件夹中创建另一个tsconfig.json,其中包含以下内容:

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "noEmit": false
  },
  "lib": ["webworker"],
  "include": ["."]
}
而且,我希望,你们知道,服务人员必须像webworker一样编译成单独的文件。
您能提供项目的链接吗?

这实际上可能有效,因为问题在于定义中的冲突(如GH中所述)。我需要几天的时间来试一下,但没必要开那么久。:)这实际上可能有效,因为问题在于定义中的冲突(如GH中所述)。我需要几天的时间来试一下,但没必要开那么久。:)
{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "noEmit": false
  },
  "lib": ["webworker"],
  "include": ["."]
}