Angular swiper gives error when compiling error TS2430: Interface 'SwiperContainerEventMap' incorrectly extends interface 'HTMLElementEventMap'

huangapple go评论55阅读模式
英文:

Angular swiper gives error when compiling error TS2430: Interface 'SwiperContainerEventMap' incorrectly extends interface 'HTMLElementEventMap'

问题

  1. 我想在 Angular 版本 15.2.8 中使用 Swiper 版本 9.3.0,并使用 npm i swiper 安装 Swiper。

  2. 根据新的 Swiper 元素 Web 组件指南,我遵循以下指南将 Swiper 注册到 Angular。

// 导入用于注册 Swiper 自定义元素的函数
import { register } from 'swiper/element/bundle';
// 注册 Swiper 自定义元素
register();

然后,我运行 Angular 命令 ng serve -o,但编译失败,出现以下错误。

error TS2430: Interface 'SwiperContainerEventMap' incorrectly extends interface 'HTMLElementEventMap'.
  Types of property '"click"' are incompatible.
    Type 'CustomEvent<any>' is missing the following properties from type 'MouseEvent': altKey, button, buttons, clientX, and 20 more.

我还在 app.module.ts 文件中添加了 schemas。

@NgModule({
  schemas: [CUSTOM_ELEMENTS_SCHEMA],

这是官方指南

如何解决这个问题?谢谢。

英文:
  1. I want to use swiper version 9.3.0 for angular version 15.2.8 and install swiper using npm i swiper
  2. As per the guide of new swiper elements web-components I follow this guide to register swiper with angular.
// import function to register Swiper custom elements
import { register } from &#39;swiper/element/bundle&#39;;
// register Swiper custom elements
register();

Then, I am running angular command ng serve -o but compilation failed and gives error like below

error TS2430: Interface &#39;SwiperContainerEventMap&#39; incorrectly extends interface &#39;HTMLElementEventMap&#39;. 
  Types of property &#39;&quot;click&quot;&#39; are incompatible.
    Type &#39;CustomEvent&lt;any&gt;&#39; is missing the following properties from type &#39;MouseEvent&#39;: altKey, button, buttons, clientX, and 20 more.

6 interface SwiperContainerEventMap extends HTMLElementEventMap {

I have added schemas inside app.module.ts file too.

@NgModule({
  schemas: [CUSTOM_ELEMENTS_SCHEMA],

Here is official guide

How to solve this problem? Thanks.

答案1

得分: 1

我们遇到了相同的问题。根据 GitHub swiper 的问题(https://github.com/nolimits4web/swiper/issues/6657),这是由于最新版本的 Angular、Typescript 和 swiper 的组合造成的。我们通过降级我们的 package.json 文件来解决这个问题。希望这能帮到你。

英文:

We had the same issue.
According to github swiper issues (https://github.com/nolimits4web/swiper/issues/6657) it us caused due to the combination of the latest versions of Angular, Typescript and swiper.

We managed to solve this by downgrading our package.json.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

{
  &quot;name&quot;: &quot;swiperjs-app&quot;,
  &quot;version&quot;: &quot;0.0.1&quot;,
  &quot;author&quot;: &quot;Ionic Framework&quot;,
  &quot;homepage&quot;: &quot;https://ionicframework.com/&quot;,
  &quot;scripts&quot;: {
    &quot;ng&quot;: &quot;ng&quot;,
    &quot;start&quot;: &quot;ng serve&quot;,
    &quot;build&quot;: &quot;ng build&quot;,
    &quot;watch&quot;: &quot;ng build --watch --configuration development&quot;,
    &quot;test&quot;: &quot;ng test&quot;,
    &quot;lint&quot;: &quot;ng lint&quot;
  },
  &quot;private&quot;: true,
  &quot;dependencies&quot;: {
    &quot;@angular/common&quot;: &quot;^15.0.0&quot;,
    &quot;@angular/core&quot;: &quot;^15.0.0&quot;,
    &quot;@angular/forms&quot;: &quot;^15.0.0&quot;,
    &quot;@angular/platform-browser&quot;: &quot;^15.0.0&quot;,
    &quot;@angular/platform-browser-dynamic&quot;: &quot;^15.0.0&quot;,
    &quot;@angular/router&quot;: &quot;^15.0.0&quot;,
    &quot;@capacitor/app&quot;: &quot;4.1.1&quot;,
    &quot;@capacitor/core&quot;: &quot;4.7.3&quot;,
    &quot;@capacitor/haptics&quot;: &quot;4.1.0&quot;,
    &quot;@capacitor/keyboard&quot;: &quot;4.1.1&quot;,
    &quot;@capacitor/status-bar&quot;: &quot;4.1.1&quot;,
    &quot;@ionic/angular&quot;: &quot;^7.0.0&quot;,
    &quot;ionicons&quot;: &quot;^7.0.0&quot;,
    &quot;rxjs&quot;: &quot;~7.5.0&quot;,
    &quot;swiper&quot;: &quot;^9.2.2&quot;,
    &quot;tslib&quot;: &quot;^2.3.0&quot;,
    &quot;zone.js&quot;: &quot;~0.11.4&quot;
  },
  &quot;devDependencies&quot;: {
    &quot;@angular-devkit/build-angular&quot;: &quot;^15.0.0&quot;,
    &quot;@angular-eslint/builder&quot;: &quot;^15.0.0&quot;,
    &quot;@angular-eslint/eslint-plugin&quot;: &quot;^15.0.0&quot;,
    &quot;@angular-eslint/eslint-plugin-template&quot;: &quot;^15.0.0&quot;,
    &quot;@angular-eslint/schematics&quot;: &quot;^15.0.0&quot;,
    &quot;@angular-eslint/template-parser&quot;: &quot;^15.0.0&quot;,
    &quot;@angular/cli&quot;: &quot;^15.0.0&quot;,
    &quot;@angular/compiler&quot;: &quot;^15.0.0&quot;,
    &quot;@angular/compiler-cli&quot;: &quot;^15.0.0&quot;,
    &quot;@angular/language-service&quot;: &quot;^15.0.0&quot;,
    &quot;@capacitor/cli&quot;: &quot;4.7.3&quot;,
    &quot;@ionic/angular-toolkit&quot;: &quot;^9.0.0&quot;,
    &quot;@types/jasmine&quot;: &quot;~4.0.0&quot;,
    &quot;@types/node&quot;: &quot;^12.11.1&quot;,
    &quot;@typescript-eslint/eslint-plugin&quot;: &quot;5.3.0&quot;,
    &quot;@typescript-eslint/parser&quot;: &quot;5.3.0&quot;,
    &quot;eslint&quot;: &quot;^7.6.0&quot;,
    &quot;eslint-plugin-import&quot;: &quot;2.22.1&quot;,
    &quot;eslint-plugin-jsdoc&quot;: &quot;30.7.6&quot;,
    &quot;eslint-plugin-prefer-arrow&quot;: &quot;1.2.2&quot;,
    &quot;jasmine-core&quot;: &quot;~4.3.0&quot;,
    &quot;jasmine-spec-reporter&quot;: &quot;~5.0.0&quot;,
    &quot;karma&quot;: &quot;~6.4.0&quot;,
    &quot;karma-chrome-launcher&quot;: &quot;~3.1.0&quot;,
    &quot;karma-coverage&quot;: &quot;~2.2.0&quot;,
    &quot;karma-coverage-istanbul-reporter&quot;: &quot;~3.0.2&quot;,
    &quot;karma-jasmine&quot;: &quot;~5.1.0&quot;,
    &quot;karma-jasmine-html-reporter&quot;: &quot;~2.0.0&quot;,
    &quot;ts-node&quot;: &quot;~8.3.0&quot;,
    &quot;typescript&quot;: &quot;~4.8.4&quot;
  },
  &quot;description&quot;: &quot;An Ionic project&quot;
}

<!-- end snippet -->

Hopefully this will help you

huangapple
  • 本文由 发表于 2023年5月10日 14:54:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76215651.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定