Could you please document typeToString, and add some comments explaining its execution?