Typesafe CustomEvents on your Frontend

Copyright: https://unsplash.com/photos/gHhWS3A-2MM

avoid CustomEvent runtime bugs by having the compiler check them for us.

Typesafe event listener example
Typesafe event producer example

TypeScript Global namespace augmentation

standard DOM `document.addEventListener` type declaration
Global augmentation example

TypeScript Conditional Types

conditional types are powerful constructs that allow us to manipulate and transform the shape of types and establish relations between them.

StrictCustomEvent proxy used to create specific CustomEvents safely

Conclusion

Scout24 Engineering

All about engineering @Scout24

Inaki Anduaga

Written by

Lead Engineer. Theoretical Physicist a long time ago. Would like to play my electric guitar very loud all day but my kids don't let me. Instead, I code…

Scout24 Engineering

All about engineering @Scout24