Created
September 25, 2019 15:45
-
-
Save danvk/673a427ba5155ad60d46cd3e6317a64b to your computer and use it in GitHub Desktop.
Errors surfaced in DOM code (for Effective TypeScript)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function handleDrag(eDown: Event) { | |
const targetEl = eDown.currentTarget; | |
targetEl.classList.add('dragging'); | |
// ~~~~~~~ Object is possibly 'null'. | |
// ~~~~~~~~~ Property 'classList' does not exist on type 'EventTarget'. | |
const dragStart = [ | |
eDown.clientX, eDown.clientY | |
// ~~~~~~~ 'clientX' does not exist on 'Event'. | |
// ~~~~~~~ 'clientY' does not exist on 'Event'. | |
]; | |
const handleUp = (eUp: Event) => { | |
targetEl.classList.remove('dragging'); | |
// ~~~~~~~~ Object is possibly 'null' | |
// ~~~~~~~~~ Property 'classList' does not exist on type 'EventTarget' | |
targetEl.removeEventListener('mouseup', handleUp); | |
// ~~~~~~~~ Object is possibly 'null'. | |
const dragEnd = [ | |
eUp.clientX, eUp.clientY | |
// ~~~~~~~ Property 'clientX' does not exist on 'Event'. | |
// ~~~~~~~ Property 'clientY' does not exist on 'Event'. | |
]; | |
console.log('dx, dy = ', [0, 1].map(i => dragEnd[i] - dragStart[i])); | |
} | |
targetEl.addEventListener('mouseup', handleUp); | |
// ~~~~~~~ Object is possibly 'null'. | |
} | |
const div = document.getElementById('surface'); | |
div.addEventListener('mousedown', handleDrag); | |
// ~~~ Object is possibly 'null'. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment