Improve the code quality of Type and add more tests.

Also optimize the implementation with a new internal sort value, to avoid some String and StringBuilder manipulations.
4 jobs for improve-type in 10 minutes and 25 seconds