Jquery不会在Typescript中监听事件

问题描述 投票:0回答:1

我正在尝试捕捉打开和关闭引导手风琴的事件,但是使用打字稿,事件不是“听取”的,但是使用JS它可以正常工作!

错误:

 module "c:/Users/THIAGOSAAD/Documents/DEVELOPMENT/NEORIS/ALIANSCE/appcomercial/build/typescript/types/jquery"
    This module can only be referenced with ECMAScript imports/exports by turning on the 'allowSyntheticDefaultImports' flag and referencing its default export.ts(2497)

JQUERY TYPES

export = jquery;
declare function jquery(w: any): any;

import * as $ from '../types/jquery';

export class BootstrapAccordionController {
    private readonly _iconStateContainer: HTMLElement;

    public constructor(private readonly _accordionID: string, public readonly iconStateContainerID: string) {
        this._iconStateContainer = document.getElementById(iconStateContainerID);
    }

    public init(): void {
        try {
            this.changeIconState();
        } catch (error) {
            console.error(error); 
        }
    }

    private changeIconState(): void {
        $(`#${this._accordionID}`).on('shown.bs.collapse',  () => this.createIconState('shown.bs.collapse'));
        $(`#${this._accordionID}`).on('hidden.bs.collapse', () => this.createIconState('hidden.bs.collapse'));
    }

    private createIconState(_stateType: string): void {
        switch(_stateType) {
            case 'shown.bs.collapse':
                this._iconStateContainer.innerHTML = `<h3 data-name="accordion-collapse-icon"><i class="fas fa-angle-up align-middle"></i></h3>`
                break;
            case 'hidden.bs.collapse':
                this._iconStateContainer.innerHTML = `<h3 data-name="accordion-collapse-icon"><i class="fas fa-angle-down align-middle"></i></h3>`
                break;
        }
    }
}
jquery typescript
1个回答
0
投票

通过打开'allowSyntheticDefaultImports'标志并引用其默认export.ts(2497),只能通过ECMAScript import / exports引用此模块

esModuleInterop设为true。这反过来也会打开合成默认导入。

© www.soinside.com 2019 - 2024. All rights reserved.