Problem: TypeScript only exists at compile-time


Problem: TypeScript only exists at compile-time.

At runtime, it's plain JS. So, when the type is only known at runtime, TypeScript can't protect you.

Solution: Validate at runtime.

Prefer runtime validation over "as".

And if you're doing a lot of runtime validation, consider using Zod.

https://github.com/colinhacks/zod

View original on X