Sometimes the best type-level code is no type-level code at all. When types become extremely complex, when they mirror external schemas (APIs, databases, protocols), or when they need to stay synchronized with changing external sources, code generation is often a better solution than sophisticated type-level programming.
Code generation trades compile-time complexity for build-time generation, often resulting in simpler, more maintainable code that stays in sync with its source of truth.
When types become too complex or must stay synchronized with external sources, generate them from schemas rather than writing sophisticated type-level code.
Используйте, когда типы становятся чрезвычайно сложными. Используйте, когда типы отражают внешние схемы. Используйте при сохранении сопоставлений типа и схемы. Используйте, когда типы требуют обширной логики уровня типа. Используйте, когда типы отклоняются от источников данных. Источник: marius-townhouse/effective-typescript-skills.