This code should be abstracted out into `TypeValue`. If it isn't already, please move it there.