Factor duplicated code for TransformTypeInObjectScope

Fixes the relevant FIXME about copy-pasted code.