Extract an emit-type-check function from common code.