Member-only story
TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize.
Discover through a simple 51-character example how and why a TypeScript type explodes to 2,000,000 and breaks your build. And fix it.
TypeScript is a very powerful and, at the same time, complicated typing language. And this causes every time we think we have it more or less under control, it surprises us with a new error that we don’t know what to do with. And it stops our compilation. Today we’ll look at TS7056, a strange error that talks about an excessively long serialization. Why? What causes it? Have I followed some bad practice? How can I avoid it elegantly?
Two million!
It turns out that this error originates when a TypeScript type needs more than two million characters to be written.
Wait, two million? Yes. Two million.
But how is that possible? Two million is a lot. You surely haven’t written anything that long in your code. And no, this error doesn’t come from the type you’ve written but from the code that TypeScript infers you’re using. That’s why the word “inferred” is in the error. And this inference is easy to neglect and make it grow. And it grows a lot, because it often…
