Extract out common typespec expansion to reduce memory consumption