The article discusses the challenges in testing complex TypeScript types and the need for assertions at the type level. It emphasizes the use of TypeScript generics and conditional types, outlining that while testing at the program level is straightforward using JavaScript methods like assert.deepEqual(), type-level assertions require a different approach. The author introduces a naive solution for type equality verification that initially appears effective but encounters issues due to TypeScript's distributive conditional types, necessitating the disabling of distribution for accurate tests.
Writing more complicated types is like programming at a different level; at program level we use JavaScript, at type level we use TypeScript.
The most crucial part of a type-level assertion API is checking whether two types are equal, which turns out to be unexpectedly difficult.
To check if two types are equal: a naive solution suggests that types X and Y are equal if certain conditions are met, but it's not that straightforward.
We need to switch off distribution in conditional types for tests like SimpleEqual to work properly, as conditional types can cause unexpected results.
Collection
[
|
...
]