Skip to main content

Hyper-Typing in TS

https://pscanf.com/s/341/

TS's type system is gradual: when you describe JS in TS, you can create types that are more or less accurate (strongly typed to any).

In pursuit of type safety, TS types will occasionally get so complex they're extremely difficult to follow/use. The author refers to this as hyper typing. We create complex types so that our functions provide devs with the correct type hint and prevent the "wild west" of any.

This tends to work and usually look good for the caller of the function, but this is what happens in the happy case. If there's an edge case, the types are a complex mess and the compilation errors are almost illegible.

The TanStack Form example is hilarious as it has 17 generic parameters and the author spends a full second or two scrolling to the right just to capture them all.

The author admits to casting various objects to any just to achieve workarounds for indigestible complex types.

The author concludes with saying that it might not be so bad for TypeScript types to be less accurate and type safe in favor of readability.