网站搜索

angular - TS2552: 无法找到名称 'PictureInPictureEvent'。您是想说 'PictureInPictureEventHandler' 吗?


我已将我的 Angular 应用从 14 升级到 15 版本。升级后我遇到了以下错误 Error: node_modules/preact/src/jsx.d.ts:1078:3 - error TS2552: Cannot find name 'PictureInPictureEvent'. Did you mean 'PictureInPictureEventHandler'?

和

node_modules/preact/src/jsx.d.ts:1124:3 - error TS2344: Type 'TargetedPictureInPictureEvent<Target>' does not satisfy the constraint 'TargetedEvent<EventTarget, Event>'.

以下是配置详情

{
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "target": "ES2022",
    "downlevelIteration": true,
    "declaration": false,
    "importHelpers": true,
    "lib": [
      "ES2022",
      "dom"
    ],
    "module": "esnext",
    "moduleResolution": "node",
    "sourceMap": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "suppressImplicitAnyIndexErrors": true,
    "typeRoots": [
      "node_modules/@types"
    ],
    "watch": false
  },
  "exclude": [
    "node_modules"
  ],
  "angularCompilerOptions": {
    "strictInjectionParameters": true
  }
}

我在这里做错了什么?

答案#1

这个问题是由于 TS 和 Preact 的版本不匹配引起的。

在尝试为不同版本更新 TS 以检查与 Preact 的兼容性之后,我仍然无法解决这个问题。

对我来说解决这个问题的方法是在 tsconfig.json 文件的 "compilerOptions" 中添加以下语句。

"skipLibCheck": true

答案#2

你需要使用 TS 4.9+ 与 Preact v10.15.0。你可以升级你的 TS 版本或降级 Preact。

你可以点击此链接,作为参考链接