TLDR Dev · ARTICLES & TUTORIALS

4 UNCONVENTIONAL WAYS TO CAST IN TYPESCRIPT

wolfgirl.dev8 min read

Summary from the TLDR Dev newsletter

This article goes over four unconventional methods to cast between types in TypeScript, showing potential unsoundness in the language's type system. These methods include abusing the `is` operator, using mutation across boundaries, exploiting structural typing, and manipulating `void` type combinations. While TypeScript generally provides good type safety, these techniques can introduce subtle bugs and unsafety.