Skip to content

EventUtils.isLeftMouseButton fails in newer typescript versions #138

@mayorovad

Description

@mayorovad

Looks like in newer versions of Typescript (i think 4.9 and above) this code is failed to transpile:

export const isLeftMouseButton = (evt: MouseEvent) => {
// Special case for mousemove and mousedown we check the buttons
// if it exists because which is 0 even if no button is pressed
if ('buttons' in evt && (evt.type === 'mousedown' || evt.type === 'mousemove')) {
return evt.buttons === 1;
}
if ('which' in evt) {
return evt.which === 1;
}
return evt.button === 1;
};

error is Error: src/util/EventUtils.ts(133,14): error TS2339: Property 'button' does not exist on type 'never'

The easiest way to reproduce is to copy this method into https://www.typescriptlang.org/play?ts=next

⚠️ What is concerning, that this error somehow ended in build of #133

The way to fix this error with minimum changes is replace 'which' in evt with evt.which !== undefined at line 130.

Possible reason - which is marked as deprecated, so 'which' in evt check now casts evt to never type

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions