Learning to Guarantee Type Correctness in Code Generation through Type-Guided Program Synthesis