Fix type warnings

This fixes almost all type warnings from the compiler. I'll be fixing the Promise interface in another pull request.