Patches taken from !6207, no-op but should make the write_type helpers more readable and flexible.
write_type