That's an interesting technique - I tested it in my Websocket code and it seems to work well; it's a little verbose, but I agree it is nice to have type safety.

I'll hold off doing a commit until tomorrow, in case you have any other comments.