英文:
Angular swiper gives error when compiling error TS2430: Interface 'SwiperContainerEventMap' incorrectly extends interface 'HTMLElementEventMap'
问题
-
我想在 Angular 版本 15.2.8 中使用 Swiper 版本 9.3.0,并使用
npm i swiper
安装 Swiper。 -
根据新的 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],
这是官方指南。
如何解决这个问题?谢谢。
英文:
- I want to use swiper version 9.3.0 for angular version 15.2.8 and install swiper using
npm i swiper
- 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 'swiper/element/bundle';
// 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 '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.
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 -->
{
"name": "swiperjs-app",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "https://ionicframework.com/",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test",
"lint": "ng lint"
},
"private": true,
"dependencies": {
"@angular/common": "^15.0.0",
"@angular/core": "^15.0.0",
"@angular/forms": "^15.0.0",
"@angular/platform-browser": "^15.0.0",
"@angular/platform-browser-dynamic": "^15.0.0",
"@angular/router": "^15.0.0",
"@capacitor/app": "4.1.1",
"@capacitor/core": "4.7.3",
"@capacitor/haptics": "4.1.0",
"@capacitor/keyboard": "4.1.1",
"@capacitor/status-bar": "4.1.1",
"@ionic/angular": "^7.0.0",
"ionicons": "^7.0.0",
"rxjs": "~7.5.0",
"swiper": "^9.2.2",
"tslib": "^2.3.0",
"zone.js": "~0.11.4"
},
"devDependencies": {
"@angular-devkit/build-angular": "^15.0.0",
"@angular-eslint/builder": "^15.0.0",
"@angular-eslint/eslint-plugin": "^15.0.0",
"@angular-eslint/eslint-plugin-template": "^15.0.0",
"@angular-eslint/schematics": "^15.0.0",
"@angular-eslint/template-parser": "^15.0.0",
"@angular/cli": "^15.0.0",
"@angular/compiler": "^15.0.0",
"@angular/compiler-cli": "^15.0.0",
"@angular/language-service": "^15.0.0",
"@capacitor/cli": "4.7.3",
"@ionic/angular-toolkit": "^9.0.0",
"@types/jasmine": "~4.0.0",
"@types/node": "^12.11.1",
"@typescript-eslint/eslint-plugin": "5.3.0",
"@typescript-eslint/parser": "5.3.0",
"eslint": "^7.6.0",
"eslint-plugin-import": "2.22.1",
"eslint-plugin-jsdoc": "30.7.6",
"eslint-plugin-prefer-arrow": "1.2.2",
"jasmine-core": "~4.3.0",
"jasmine-spec-reporter": "~5.0.0",
"karma": "~6.4.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.2.0",
"karma-coverage-istanbul-reporter": "~3.0.2",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.0.0",
"ts-node": "~8.3.0",
"typescript": "~4.8.4"
},
"description": "An Ionic project"
}
<!-- end snippet -->
Hopefully this will help you
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论