AI Hints
Home›TypeScript Tutorial›Habits and Library Types
TypeScript · Lesson 113 of 120

Performance of Types

Keep it simple.

⏱ 2 min read▶ Video at 1:29:23🎓 Free
Watch this lesson in the TypeScript courseWatch on YouTube ↗Full TypeScript course

Very clever types can slow down the compiler and your editor, and confuse your teammates. Most of the time, simple types are the best types.

Performance of Types
From the video: Performance of Types
  • Clever types
  • Slow and confusing
  • Simple is best

Keeping it fast

Name complex types with aliases or interfaces, so the compiler can reuse them. Avoid deeply recursive conditional types. Prefer interfaces when extending objects. And add return types to big exported functions.

keyvalue
Namecomplex types
Avoiddeep recursion
Extendwith interfaces
Exportsexplicit return types

Keeping it readable

If a type needs a long comment to explain, simplify it. A little repetition is better than a puzzle. Write types for the reader, not to show off.

keyvalue
Long explanationsimplify
Repetitionsometimes fine
Audiencethe reader
Goalclear, not clever

Summary

Simple, named types keep the compiler fast, and your team happy. Next, reading library types.

Key takeaways
  • Name types
  • Avoid deep recursion
  • Clear, not clever
Next up: Reading Library Types — understand .d.ts