All Topics
All Topics
Technology
Technology
Design
Design
Programming
Programming
Science
Science
News
News
Gaming
Gaming
Entertainment
Entertainment
Business
Business
Finance
Finance
Sports
Sports
Health
Health
Food
Food
Travel
Travel
Art
Art
Music
Music
Books
Books
Education
Education
Politics
Politics
Personal
Personal
No algorithm. No AI slop. No ads. Just RSS. Pro-human. Indie writers. Real journalism. Open web. Chronological. Hand toasted.

Unconventional Type Casting Techniques in TypeScript

By

Bogdanp

7mo ago· 8 min readen

Summary

This article explores unconventional methods for type casting in TypeScript, moving beyond the standard 'as' operator. It presents various creative approaches to casting between arbitrary types, including using unknown as an intermediate type, function signatures, and other TypeScript type system features. The content is technical and aimed at TypeScript developers looking to understand the language's type system more deeply and discover alternative casting techniques.

Key quotes

· 3 pulled
We can't just directly do a as B because Typescript is smart enough to warn us about that, at least.
If this was intentional, convert the expression to 'unknown' first.
If we were approaching this from a type theoretic perspective, it's already interesting.
Snippet from the RSS feed
I saw a post by qntm and remembered I had a playground with a similar idea. I then expanded that playground into a (probably non-exhausti...

You might also wanna read