Type theory serves as a foundation for mathematics by providing a framework for constructing, organising, and reasoning about mathematical objects and proofs, ensuring consistency and avoiding paradoxes inherent in set theory.