我正在尝试捕捉打开和关闭引导手风琴的事件,但是使用打字稿,事件不是“听取”的,但是使用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;
}
}
}
通过打开'allowSyntheticDefaultImports'标志并引用其默认export.ts(2497),只能通过ECMAScript import / exports引用此模块
将esModuleInterop
设为true
。这反过来也会打开合成默认导入。