`@HostListener` of `e: TouchEvent` causes Firefox to crash with "ReferenceError: TouchEvent is not defined." `@HostListener` of `e: TouchEvent` causes Firefox to crash with "ReferenceError: TouchEvent is not defined." angular angular

`@HostListener` of `e: TouchEvent` causes Firefox to crash with "ReferenceError: TouchEvent is not defined."


When there is decorator on a method, typescript compiler stores types of parameters in the metadata, which fails in desktop Firefox because TouchEvent is not defined there. It can be solved by polyfilling the missing types with stubs. Just add the following code to polyfills.ts

for (const type of ['TouchEvent']) {    if (typeof window[type] === 'undefined') {        window[type] = function () { };    }}

To polyfill other types, add them to the list. A word of warning - this may break code that checks for existence of touch events by detecting window.TouchEvent.

Anyway, the problem only seems to happen with the JIT compiler, so it will probably disappear with Ivy.


You can tell Angular not to emit decorator metadata in tsconfig.json:"emitDecoratorMetadata": false