How can I see how TypeScript computes types? How can I see how TypeScript computes types? typescript typescript

How can I see how TypeScript computes types?


There isn't any built-in mechanism in typescript to log out the desired info in question. However, if you are interested in understanding internal work, here's the place in source code where the actually resolving of conditional types happens.

Take a look at these places in checker.ts.

ln:13258 instantiateTypeWorker()
ln:12303 getConditionalType()
ln:12385 getTypeFromConditionalTypeNode()
ln:12772 getTypeFromTypeNode()


Attached is a half-done typescript plugin I put together carelessly. It logs out the raw data structure of a ConditionalType. To understand this struct, check types.ts ln:4634.

UX of this plugin is terrible, but that struct does tell you how typescript decides the final value of a conditional type.