Argument of type '(e: CustomEvent) => void' is not assignable to parameter of type 'EventListenerOrEventListenerObject'

前端 未结 4 1093
执笔经年
执笔经年 2021-02-07 04:11

I have this custom event setup, and it works with TypeScript 2.5.3, but when I updated to 2.6.1 I get an error

window.addEventListener(         


        
4条回答
  •  执念已碎
    2021-02-07 04:57

    Building off of jcalz's excellent answer, you can also use a type assertion to be a little cleaner:

    window.addEventListener('OnRewards', (e: Event) => {
        const detail = (e).detail;
        ...
    });
    

提交回复
热议问题