Storybook 构建失败,出现 TS 错误“接口‘Event’错误地扩展了 Angular 中的接口‘KeyboardEvent’”

Tom*_*ava 3 typescript angular storybook angular-storybook

我在我的 Angular 项目中安装了 Storybook,一切正常,直到今天,当我运行时,yarn install这个 Storybook 构建失败并出现以下 TS 错误

node_modules/@storybook/api/dist/ts3.9/modules/shortcuts.d.ts:55:18 - 错误 TS2430:接口“Event”错误地扩展了接口“KeyboardEvent”。呃!属性“目标”的类型不兼容。呃!类型 '{ tagName: string; 中缺少属性 'prototype' addEventListener(): 无效; 删除事件监听器():布尔值;调度事件(事件:事件):布尔值;getAttribute(attr: string): 字符串 | 无效的; }',但在“EventTarget”类型中是必需的。呃!呃!55 导出接口Event extends KeyboardEvent { 错误!~~~~~ 错误!呃!node_modules/typescript/lib/lib.dom.d.ts:5144:5 错误!第5144章 原型:EventTarget;呃!~~~~~~~~~ 错误!“原型”在这里声明。块引用

包.json

  "name": "tour",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test",
    "docs:json": "compodoc -p ./tsconfig.json -e json -d .",
    "storybook": "npm run docs:json && start-storybook -p 6006",
    "build-storybook": "npm run docs:json && build-storybook"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^14.1.0",
    "@angular/common": "^14.1.0",
    "@angular/compiler": "^14.1.0",
    "@angular/core": "^14.1.0",
    "@angular/forms": "^14.1.0",
    "@angular/platform-browser": "^14.1.0",
    "@angular/platform-browser-dynamic": "^14.1.0",
    "@angular/router": "^14.1.0",
    "rxjs": "~7.5.0",
    "tslib": "^2.3.0",
    "zone.js": "~0.11.4"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^14.1.0",
    "@angular/cli": "~14.1.0",
    "@angular/compiler-cli": "^14.1.0",
    "@babel/core": "^7.19.3",
    "@compodoc/compodoc": "^1.1.19",
    "@storybook/addon-actions": "^6.5.12",
    "@storybook/addon-essentials": "^6.5.12",
    "@storybook/addon-interactions": "^6.5.12",
    "@storybook/addon-links": "^6.5.12",
    "@storybook/angular": "^6.5.12",
    "@storybook/builder-webpack5": "^6.5.12",
    "@storybook/manager-webpack5": "^6.5.12",
    "@storybook/testing-library": "^0.0.13",
    "@types/jasmine": "~4.0.0",
    "babel-loader": "^8.2.5",
    "jasmine-core": "~4.2.0",
    "karma": "~6.4.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.2.0",
    "karma-jasmine": "~5.1.0",
    "karma-jasmine-html-reporter": "~2.0.0",
    "typescript": "~4.7.2"
  }
}
Run Code Online (Sandbox Code Playgroud)

角度.json

  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "tour": {
      "projectType": "application",
      "schematics": {},
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/tour",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.css"
            ],
            "scripts": []
          },
          "configurations": {
            "production": {
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "500kb",
                  "maximumError": "1mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "2kb",
                  "maximumError": "4kb"
                }
              ],
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "outputHashing": "all"
            },
            "development": {
              "buildOptimizer": false,
              "optimization": false,
              "vendorChunk": true,
              "extractLicenses": false,
              "sourceMap": true,
              "namedChunks": true
            }
          },
          "defaultConfiguration": "production"
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "configurations": {
            "production": {
              "browserTarget": "tour:build:production"
            },
            "development": {
              "browserTarget": "tour:build:development"
            }
          },
          "defaultConfiguration": "development"
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "tour:build"
          }
        },
        "storybook": {
          "builder": "@storybook/angular:start-storybook",
          "options": {
            "browserTarget": "tour:build",
            "port": 6006
          }
        },
        "build-storybook": {
          "builder": "@storybook/angular:build-storybook",
          "options": {
            "browserTarget": "tour:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.spec.json",
            "karmaConfig": "karma.conf.js",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.css"
            ],
            "scripts": []
          }
        }
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

以前有人遇到过这种情况吗?知道我在这里做错了什么吗?

小智 5

在我的项目中,问题是依赖

\n
\n

"@types/node": "^18.7.23"

\n
\n

删除插入符号:

\n
\n

“@类型/节点”:“18.7.23”

\n
\n

问题已经消失。\n(^版本 \xe2\x80\x9c 与版本\xe2\x80\x9d 兼容,将更新您到所有未来的次要/补丁版本,而不增加主要版本。^2.3.4 将使用版本从 2.3.4 到 <3.0.0. --> package.json 中的波浪号 (~) 和脱字号 (^) 有什么区别? )

\n