🚀 Day 07 of Learning TypeScript — Type Guards & Static Keyword Today I explored two important concepts in TypeScript that make code more robust and structured. 🔹 1. Type Guards Type Guards help TypeScript narrow down types so we can safely work with variables. They make sure we use the right operations on the right type. ✨ Example: function checkValue(value: string | number) { if (typeof value === "string") { console.log(value.toUpperCase()); } else { console.log(value.toFixed(2)); } } 📌 TypeScript understands the type based on conditions like: typeof instanceof 🔹 2. static Keyword in TypeScript The static keyword is used to define properties or methods that belong to the class itself, not to its instances. 📌 No need to create an object to use static methods! ⭐ Key Takeaways ✔ Type Guards make code safer and prevent runtime errors ✔ static helps organize utility methods inside classes ✔ TypeScript keeps improving code clarity and structure Learning step-by-step and enjoying the process 🚀 More concepts coming soon! #typescript #javascript #webdevelopment #learninginpublic #frontend #developers #codingjourney
Type Guards & Static Keyword in TypeScript Explained
More Relevant Posts
-
🚀 Day 08 of Learning TypeScript — Generics & keyof Today I explored two powerful features in TypeScript that make code more flexible and type-safe. 🔹 1. Generics — Write reusable & flexible code Generics allow us to write functions/components that work with multiple types without losing type safety. ✨ Example:- function identity<T>(value: T): T { return value; } const result = identity<string>("Hello TypeScript"); 📌 Instead of fixing a type, we make it dynamic using <T>. 🔹 2. keyof Operator — Work with object keys safely keyof helps us get all the keys of an object as a type. ✨ Example:- type User = { name: string; age: number; }; function getValue(obj: User, key: keyof User) { return obj[key]; } 📌 Now only valid keys (name, age) are allowed → no runtime errors. ⭐ Key Takeaways ✔ Generics make code reusable and scalable ✔ keyof ensures safe access to object properties ✔ Together, they help write strongly typed and flexible logic Learning TypeScript step-by-step and loving how it improves code quality 🚀 👉 What’s your favorite TypeScript feature so far? #typescript #javascript #webdevelopment #learninginpublic #frontend #codingjourney #developers
To view or add a comment, sign in
-
🚀 Day 09 of Learning TypeScript — Utility Types & Namespaces Continuing my TypeScript journey, today I went deeper into Utility Types and explored a new concept: Namespaces. 🔹 1. Utility Types (Deep Dive) TypeScript provides powerful built-in utility types that help transform existing types efficiently. // Make all properties optional type PartialUser = Partial<User>; 📌 These utilities reduce code duplication and improve scalability. 🔹 2. Namespaces — Organizing Code Namespaces help in organizing code into logical groups, especially in large applications. ✨ Example: namespace UserUtils { export function greet(name: string) { return `Hello, ${name}`; } } console.log(UserUtils.greet("Rohit")); 📌 Useful for structuring code and avoiding naming conflicts. ⭐ Key Takeaways ✔ Utility types simplify type transformations ✔ Helps write cleaner and maintainable code ✔ Namespaces organize code logically ✔ TypeScript is not just typing — it’s structuring code better Learning step-by-step and building consistency 🚀 👉 Do you prefer modules or namespaces in TypeScript? #typescript #javascript #webdevelopment #learninginpublic #frontend #developers #codingjourney
To view or add a comment, sign in
-
-
📘 Day 03 of Learning TypeScript — 🚀 Today was all about diving deeper into TypeScript and understanding how TS makes JavaScript safer, cleaner, and smarter. Some major concepts clicked today—especially around type narrowing and type assertions. 🔥 What I Learned Today ✅ 1. Type Narrowing I understood how TypeScript becomes smart based on conditions: 🏹 typeof 🏹 instanceof 🏹 truthiness checks 🏹 switch-case narrowing This helps TS auto-detect whether a value is a string, number, or a specific object type. ✅ 2. Custom Type Guards ✅ 3. Discriminated Union Types Learnt how to create multiple object variations like Masala, Ginger, Elaichi Chai and use the type field for precise narrowing. ✅ 4. Type Assertions (as) Practiced: ✔ Converting any → specific type ✔ Using assertion with JSON.parse() ✔ DOM element type assertion like as HTMLInputElement ✅ 5. Safe Error Handling if (error instanceof Error) to safely access error details. 🧠 Key Takeaway TypeScript isn’t just about types — It’s about making JavaScript predictable, reliable, and professional. Let’s keep going! 💪 #TypeScript #LearningJourney #100DaysOfCode #WebDevelopment #JavaScript #React #DeveloperJourney
To view or add a comment, sign in
-
-
Day 01 of Learning TypeScript 🚀 Today I covered some core fundamentals of TypeScript, and it already feels like I’m writing cleaner and safer code. Here’s what I learned today 👇 🔹 1. Installation & Setup Installed TypeScript globally Created my first .ts file Used tsc to compile & run the code 🔹 2. Type Inference TypeScript can automatically detect types: let age = 20; // inferred as number This reduces boilerplate and prevents type errors. 🔹 3. Primitive Data Types number string boolean null undefined bigint symbol 🔹 4. Special Types any → flexible but unsafe unknown → safer than any void → used in function void clearly expresses that a function does something but returns nothing. never → for unreachable code 🔹 4. Why avoid any I also learned that any removes all type-checking. Basically, it turns TypeScript back into JavaScript. ❌ Avoid using any unless absolutely required. ✔ Prefer unknown for safer typing. Small takeaway: TypeScript gives structure and catches mistakes before you run the code. Even these basics already feel much more reliable than plain JS. #typescript #javascript #learninginpublic #webdevelopment #frontend
To view or add a comment, sign in
-
Started noticing one thing in modern MERN projects — TypeScript is everywhere 👀💙 At first, JavaScript feels easy… Then bugs start appearing from “somewhere” 😅 That’s where TypeScript steps in — better code clarity, fewer surprises, and cleaner projects ✨💻 Still learning it step by step… but honestly, it feels worth it 🚀 #MERNStack #TypeScript #WebDevelopment #Learning #StudentDeveloper
To view or add a comment, sign in
-
-
💡 Use arrow functions for concise, readable code in modern JavaScript. ────────────────────────────── 🚀 JavaScript Insight #1: Arrow Functions Unleashed #javascript #arrowfunctions #es6 ────────────────────────────── ## Core Concept Arrow functions provide a shorter syntax and lexical this binding. 📋 Key Rules (Read or Regret) • No own this or arguments. • Great for callbacks and array methods. • Avoid as object methods. 💡 Try This ```js const add = (a, b) => a + b; ``` 🔑 Key Takeaway Arrow functions = less code, more clarity! #javascript #es6 #tips ────────────────────────────── 🤖 Written with GitHub Copilot — where code meets wit. 🔗 Full guide & code: https://lnkd.in/g-UmsSjc
To view or add a comment, sign in
-
Just wrapped up learning the fundamentals of TypeScript, and honestly—it’s changed how I think about writing JavaScript 🚀 At first, it felt like extra work 🤯 Adding types, fixing errors I didn’t “need” to fix… but once it clicked, it started saving me time instead of costing it. Here’s what stood out for me: Fewer bugs 🐛❌ → catching mistakes while coding instead of at runtime Better readability 📖 → my code explains itself more clearly Stronger confidence 💪 → refactoring doesn’t feel risky anymore Improved developer experience ⚡ → autocomplete + type hints are a game changer TypeScript doesn’t just make code “safer”—it makes you more intentional as a developer 🧠 Still learning, still building, but definitely glad I added this to my toolkit 🔧 #TypeScript #JavaScript #WebDevelopment #LearningInPublic #DeveloperJourney
To view or add a comment, sign in
-
-
Day 47 of the #100DaysOfCodeChallenge Today I started learning TypeScript. Since most modern large-scale applications are moving towards TypeScript, I decided it’s important to understand it properly instead of only relying on JavaScript. Today I explored the fundamentals: What TypeScript is and why it is used How static typing helps catch errors before runtime Basic types like string, number, boolean, arrays, and objects Understanding interfaces and type safety How TypeScript improves code readability and maintainability One thing I realized is that TypeScript doesn't replace JavaScript — it actually enhances JavaScript by adding type safety and better structure, which becomes very useful when working on large or collaborative projects. Right now I’m just getting comfortable with the basics, but I know mastering TypeScript will help me write more reliable and scalable code in the future. 💡 Quote of the day: "The best developers are not the ones who write the most code, but the ones who understand their code the most." Step by step improving the developer toolkit 🚀 #100DaysOfCode #TypeScript #JavaScript #WebDevelopment #LearningJourney
To view or add a comment, sign in
-
-
Day 2 of my TypeScript learning journey 🚀 Today I went deeper into some of the most important OOP and type system concepts in TypeScript — classes, access modifiers, static members, interfaces, and generics (including multiple generic types). What stood out to me is how practical these concepts are in real-world development: Classes help us model real-world entities like users, payments, or services in a structured way, making large applications easier to manage and scale. Access modifiers (public, private, protected) help in controlling how data is accessed, which improves security and prevents unintended changes in code. Static members are useful for utility-based logic where we don’t need multiple instances, just shared functionality across the application. Interfaces define clear contracts between different parts of an application, which is extremely important when working in teams or building scalable systems. Generics allow us to write flexible yet type-safe code that can work with different data types without losing structure or reliability. Overall, these concepts are not just “TypeScript features” — they are essential tools for writing professional, scalable, and maintainable software. Excited to continue building and applying these concepts in real projects 💻🚀 #TypeScript #JavaScript #WebDevelopment #Programming #CodingJourney #100DaysOfCode #SoftwareDevelopment #FrontendDevelopment #BackendDevelopment #LearnToCode
To view or add a comment, sign in
-
🚀 Day 4 of Learning TypeScript Today I dove deeper into one of the most powerful aspects of TypeScript — its type system. Things are starting to click, and I’m beginning to see how TypeScript helps write safer and more predictable code. 🔍 What I explored today: • Type Narrowing Understanding how TypeScript intelligently narrows down types based on conditions makes handling dynamic data much safer. • Type Guards Using typeof and instanceof to control type flow feels like giving JavaScript superpowers. • Discriminated Unions A clean and scalable way to manage complex conditional logic. This was a game changer! 🧰 Utility Types: • Partial – makes all properties optional • Required – makes all properties mandatory • Readonly – prevents modification • Pick & Omit – selecting and excluding properties • Record – creating structured object types ⚡ Advanced Generics: • Conditional Types – types that depend on conditions • Mapped Types – transforming existing types • keyof & typeof – building dynamic and reusable type systems 💡 Key Takeaway: TypeScript isn’t just about types — it’s about designing better, scalable, and maintainable code. On to Day 5 🔥 #TypeScript #WebDevelopment #FullStackDeveloper #LearningInPublic #JavaScript #CodingJourney
To view or add a comment, sign in
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development