A type safe publish subscribe API in JavaScript