【问题标题】:Importing interactjs in vuejs + typescript project generate type checking errorsvuejs + typescript项目中导入interactjs会产生类型检查错误
【发布时间】:2021-06-29 07:35:46
【问题描述】:

我有一个 vuejs + typescript 项目,一旦我添加了 interactjs 包,vue cli 编译就会显示这些类型错误:

    > ERROR in web/node_modules/@interactjs/types/index.d.ts(267,18):
267:18 All declarations of 'BaseEvent' must have identical type parameters.
    265 |     import type { Interaction, InteractionProxy } from "@interactjs/core/Interaction";
    266 |     import type { ActionName } from "@interactjs/core/scope";
  > 267 |     export class BaseEvent<T extends ActionName | null = never> {
        |                  ^
    268 |         type: string;
    269 |         target: EventTarget;
    270 |         currentTarget: Node;
ERROR in web/node_modules/@interactjs/types/index.d.ts(287,22):
287:22 All declarations of 'BaseEvent' must have identical type parameters.
    285 |         stopImmediatePropagation(): void;
    286 |     }
  > 287 |     export interface BaseEvent<T extends ActionName> {
        |                      ^
    288 |         interaction: InteractionProxy<T>;
    289 |     }
    290 | }
ERROR in /node_modules/@interactjs/types/index.d.ts(2487,34):
2487:34 Type 'T' does not satisfy the constraint '"drag" | "drop" | "resize" | "gesture"'.
  Type '"drag" | "drop" | "resize" | "gesture" | null' is not assignable to type '"drag" | "drop" | "resize" | "gesture"'.
    Type 'null' is not assignable to type '"drag" | "drop" | "resize" | "gesture"'.
      Type 'T' is not assignable to type '"gesture"'.
        Type '"drag" | "drop" | "resize" | "gesture" | null' is not assignable to type '"gesture"'.
          Type 'null' is not assignable to type '"gesture"'.
    2485 |             eventTarget: Node;
    2486 |         };
  > 2487 |         prevEvent: InteractEvent<T, EventPhase>;
         |                                  ^
    2488 |         pointerIsDown: boolean;
    2489 |         pointerWasMoved: boolean;
    2490 |         _interacting: boolean;
ERROR in /node_modules/@interactjs/types/index.d.ts(2588,135):
2588:135 Type 'T' does not satisfy the constraint '"drag" | "drop" | "resize" | "gesture"'.
  Type 'T' is not assignable to type '"gesture"'.
    2586 |         _updateLatestPointer(pointer: PointerType, event: PointerEventType, eventTarget: Node): void;
    2587 |         destroy(): void;
  > 2588 |         _createPreparedEvent<P extends EventPhase>(event: PointerEventType, phase: P, preEnd?: boolean, type?: string): InteractEvent<T, P>;
         |                                                                                                                                       ^
    2589 |         _fireEvent<P extends EventPhase>(iEvent: InteractEvent<T, P>): void;
    2590 |         _doPhase<P extends EventPhase>(signalArg: Omit<DoPhaseArg<T, P>, 'iEvent'> & {
    2591 |             iEvent?: InteractEvent<T, P>;
ERROR in /web/node_modules/@interactjs/types/index.d.ts(2589,64):
2589:64 Type 'T' does not satisfy the constraint '"drag" | "drop" | "resize" | "gesture"'.
  Type 'T' is not assignable to type '"gesture"'.
    2587 |         destroy(): void;
    2588 |         _createPreparedEvent<P extends EventPhase>(event: PointerEventType, phase: P, preEnd?: boolean, type?: string): InteractEvent<T, P>;
  > 2589 |         _fireEvent<P extends EventPhase>(iEvent: InteractEvent<T, P>): void;
         |                                                                ^
    2590 |         _doPhase<P extends EventPhase>(signalArg: Omit<DoPhaseArg<T, P>, 'iEvent'> & {
    2591 |             iEvent?: InteractEvent<T, P>;
    2592 |         }): boolean;
ERROR in /node_modules/@interactjs/types/index.d.ts(2590,67):
2590:67 Type 'T' does not satisfy the constraint '"drag" | "drop" | "resize" | "gesture"'.
  Type 'T' is not assignable to type '"gesture"'.
    2588 |         _createPreparedEvent<P extends EventPhase>(event: PointerEventType, phase: P, preEnd?: boolean, type?: string): InteractEvent<T, P>;
    2589 |         _fireEvent<P extends EventPhase>(iEvent: InteractEvent<T, P>): void;
  > 2590 |         _doPhase<P extends EventPhase>(signalArg: Omit<DoPhaseArg<T, P>, 'iEvent'> & {
         |                                                                   ^
    2591 |             iEvent?: InteractEvent<T, P>;
    2592 |         }): boolean;
    2593 |         _now(): number;
ERROR in /node_modules/@interactjs/types/index.d.ts(2591,36):
2591:36 Type 'T' does not satisfy the constraint '"drag" | "drop" | "resize" | "gesture"'.
  Type 'T' is not assignable to type '"gesture"'.
    2589 |         _fireEvent<P extends EventPhase>(iEvent: InteractEvent<T, P>): void;
    2590 |         _doPhase<P extends EventPhase>(signalArg: Omit<DoPhaseArg<T, P>, 'iEvent'> & {
  > 2591 |             iEvent?: InteractEvent<T, P>;
         |                                    ^
    2592 |         }): boolean;
    2593 |         _now(): number;
    2594 |     }

这不会阻止执行但构建失败。 我尝试使用 es6 包 @interactjs/interact, @interactjs/actions, ...但它是一样的。

我创建了新的 vue 空项目并仅添加了 interactjs 以在错误声明中有一个代码示例,但一切正常。所以我在我的项目中使用了相同版本的interactjs、typescript和所有vue包,但我一直看到这个问题。

这里是我在 package.json 中的包,以防你们中的任何人知道包之间存在冲突

"dependencies": {
    "@aws-amplify/auth": "^3.4.14",
    "@aws-amplify/core": "^3.8.6",
    "@fortawesome/fontawesome-svg-core": "^1.2.27",
    "@fortawesome/pro-duotone-svg-icons": "^5.12.1",
    "@fortawesome/pro-light-svg-icons": "^5.12.1",
    "@fortawesome/pro-regular-svg-icons": "^5.12.1",
    "@fortawesome/pro-solid-svg-icons": "^5.12.1",
    "@fortawesome/vue-fontawesome": "^0.1.9",
    "async-mutex": "^0.3.1",
    "aws-sdk": "^2.805.0",
    "axios": "^0.19.2",
    "core-js": "^3.6.5",
    "echarts": "^5.0.2",
    "hls-parser": "^0.6.1",
    "hls.js": "^1.0.2",
    "interactjs": "^1.10.11",
    "platform": "^1.3.6",
    "resize-observer": "^1.0.0",
    "rxjs": "^6.5.4",
    "wavesurfer.js": "^3.3.1",
    "ts-ebml": "^2.0.2",
    "v-tooltip": "^2.1.3",
    "vue": "^2.6.11",
    "vue-class-component": "^7.2.3",
    "vue-i18n": "^8.24.4",
    "vue-meta": "^2.4.0",
    "vue-property-decorator": "^9.1.2",
    "vue-router": "^3.2.0",
    "vuex": "^3.4.0",
    "vuex-class": "^0.3.2"
  },
  "devDependencies": {
    "@types/dom-mediacapture-record": "^1.0.6",
    "@types/gapi.auth2": "0.0.50",
    "@types/hls-parser": "^0.5.1",
    "@types/mime-types": "^2.1.0",
    "@types/node": "^15.12.5",
    "@types/platform": "^1.3.3",
    "@types/resize-observer-browser": "^0.1.4",
    "@types/wavesurfer.js": "^3.3.1",
    "@types/webrtc": "0.0.25",
    "@typescript-eslint/eslint-plugin": "^4.18.0",
    "@typescript-eslint/parser": "^4.18.0",
    "@vue/cli-plugin-babel": "~4.5.0",
    "@vue/cli-plugin-eslint": "~4.5.0",
    "@vue/cli-plugin-router": "~4.5.0",
    "@vue/cli-plugin-typescript": "~4.5.0",
    "@vue/cli-plugin-vuex": "~4.5.0",
    "@vue/cli-service": "~4.5.0",
    "@vue/eslint-config-airbnb": "^5.0.2",
    "@vue/eslint-config-typescript": "^7.0.0",
    "chunks-webpack-plugin": "^7.0.0",
    "css-loader": "^3.5.3",
    "eslint": "^6.7.2",
    "eslint-plugin-import": "^2.20.2",
    "eslint-plugin-vue": "^6.2.2",
    "file-loader": "^6.0.0",
    "html-webpack-inline-source-plugin": "0.0.10",
    "html-webpack-plugin": "^4.3.0",
    "mime-types": "^2.1.27",
    "mini-css-extract-plugin": "^0.9.0",
    "optimize-css-assets-webpack-plugin": "^5.0.3",
    "remove-files-webpack-plugin": "1.4.4",
    "sass": "^1.35.1",
    "sass-loader": "^8.0.2",
    "ts-loader": "^7.0.4",
    "tsconfig-paths-webpack-plugin": "^3.2.0",
    "typescript": "~4.1.5",
    "url-loader": "^4.1.0",
    "vue-template-compiler": "^2.6.11",
    "webpack": "^4.46.0",
    "webpack-cli": "^3.3.11",
    "worker-loader": "^3.0.5",
    "ws": "^6.2.1"
  }

【问题讨论】:

    标签: typescript interactjs


    【解决方案1】:

    听起来您也需要安装类型。 npm install --save-dev @interactjs/types。应该做的伎俩。

    https://github.com/taye/interact.js#typescript-definitions

    【讨论】:

    • 这个包是interactjs的依赖,已经安装好了。即使我安装它,我也会遇到同样的错误。
    【解决方案2】:

    我通过在 tsconfig.js 中添加这一行找到了一个“解决方案”

    "skipLibCheck": true
    

    【讨论】:

      猜你喜欢
      • 2020-12-18
      • 2021-04-29
      • 1970-01-01
      • 1970-01-01
      • 2021-03-29
      • 2020-06-26
      • 1970-01-01
      • 2020-09-04
      • 2021-09-01
      相关资源
      最近更新 更多