If you are under the Civil Service Retirement System you always are fully vested—that is, you have the right to access all of the money in your account under the TSP’s withdrawal rules—since your entire account consist of money you invested and its associated earnings.
If you are under FERS, you always are vested in your own investments, in agency matching contributions, and the associated earnings for each. You generally are vested in agency automatic contributions and their earnings after three years of civilian federal service—two years for certain positions, mainly involving working for Congress. (Note: Those restrictions don’t apply in cases of death in service.) If you leave government service before meeting the vesting requirement for your automatic contributions, those contributions and their earnings will be forfeited to the TSP.