Make querySelector in kotlin-js more convenient and type-safe
"Would be cool somehow, to "default" base type to Element if none is specified, but can't think of way to do that." Indeed it is not possible to do that, at least not with the same method. An option could be to have a separate method for that. document.queryHtmlSelectorRaw ? Or wait, actually... That leaves you back to what you were starting with, Element.querySelector.


  I'd like something, that can pretty much replace original function and just add benefits of stronger typing and nicer error message. Any hints on how to improve this are greatly appreciated.


Given those requirements, I'd say that the current methods is about as good as you're gonna get. You have the stronger typing (but you will have to specify it). You have the better error message if it's null.

The only things that I would consider are:


Get rid of reified, I'm not convinced that you need it.
Change method names, queryHtmlSelector can easily be confused with the built in querySelector. May I recommend just the name selector or select?
Improve the error message even further, such as No element found using selector '$selector' on $this.