DEV Community

Kayes Molla Dev
Kayes Molla Dev

Posted on

🚀 **Today I Learned: Literal Types & Type Assertions in TypeScript**
Today, I explored two useful TypeScript concepts:
**1. Literal Types**
**2. Assertion **
#TypeScript #JavaScript #WebDevelopment #LearningInPublic #FrontendDevelopment

Top comments (1)

Collapse
 
kayes_molladev_ec68d9c62 profile image
Kayes Molla Dev •

Today, I explored two useful TypeScript concepts:

  1. Literal Types

Literal types allow us to restrict a variable to specific values. I learned how const and let affect type inference and why explicitly defining a union type can be useful.

  1. Type Assertions

The as keyword tells TypeScript to treat a value as a specific type. However, assertions don't perform runtime validation.

I also explored unknown, custom type guards, and type predicates to validate data safely before accessing its properties.

Key Takeaway: Understanding type inference and runtime validation helps us write safer and more reliable TypeScript code.

Still learning, practicing, and improving every day! 💻

TypeScript #JavaScript #WebDevelopment #LearningInPublic #FrontendDevelopment