Basic typescript checking and subtyping, and factored out check_app