Let’s talk about something that makes TypeScript feel almost like a programming language at the type level - 'Recursion in Mapped Types.' Imagine you have a deeply nested object type. Some properties are objects. Some are objects inside objects. Some are arrays of objects. Now your task is simple in words - 'Make everything optional. Even nested properties.' At first, this feels easy. We already know about 'Partial<T>' utility type. But 'Partial' only works at the first level. It does not go deep. Nested properties remain required. So how do we make everything optional at every level? This is where recursion comes in. In normal programming, recursion means a function calls itself. In TypeScript types, recursion means a type references itself inside its own definition. That’s it. So, how do we solve the problem with a deeply nested object? We can define a type that iterates over each property of an object, makes it optional, and if the property itself is an object, apply the same logic again. This 'apply the same logic again' part is recursion. But how does this even work? Here’s something fascinating about TypeScript. When a mapped type is applied to a primitive type like string or number, TypeScript simply returns that primitive type. It does not try to iterate over it. This behavior is intentional and baked into the type system. That’s why recursive mapped types don’t break when they eventually reach primitive properties. For example, when recursion hits 'string', it just stops naturally. That’s elegant. Recursion in mapped types is where TypeScript stops being static typing, and starts feeling like a type transformation engine. #Programming #TypeScript #JavaScript #WebDevelopment #Coding
Recursion in Mapped Types: Making Nested Properties Optional in TypeScript
More Relevant Posts
-
Day 70 of #100daysofcode Today I'll just be posting about a really great article that helped me better understand object oriented programming in JavaScript. At the end of the day, classes are just functions in JavaScript that return objects which contain prototypes. Prototypes store the methods and properties that can be accessed by all object instances of a particular class. This article below discusses more about object prototypes, getters, setters, and so much more! https://lnkd.in/d_NE3aTH In my next post, I will be posting the project requirements for my small todo list application.
To view or add a comment, sign in
-
Most of us use asynchronous programming in JavaScript almost every day. We use it to fetch data from databases, call APIs, or handle operations that might block the main thread. But how often do we stop and think about what actually happens behind the scenes? In this blog, I’m sharing my key learnings and breaking down the fundamentals of asynchronous programming in JavaScript. Read here 👇 https://lnkd.in/dxKYzhNz Do visit my GitHub repo for JavaScript where you can find multiple topic that I have covered so far: https://lnkd.in/duYbatKd
To view or add a comment, sign in
-
🚀 Just published a new blog on Understanding Object-Oriented Programming (OOP) in JavaScript. In this article, I explain the basics of OOP, including what classes are, how to create objects using classes, the constructor method, and methods inside a class. I also used simple real-world examples like blueprints and objects to make the concept easy to understand. 📖 Read the full article here: https://lnkd.in/gKUGBNMR Inspired by the amazing teaching of Hitesh Choudhary Sir and Piyush Garg Sir from Chai Aur Code . ☕💻 #javascript #webdevelopment #oop #learninginpublic #chaiAurCode
To view or add a comment, sign in
-
Just published a new blog on Object-Oriented Programming in JavaScript. In this article, I break down OOP fundamentals using simple examples and real world analogies. Covered topics: • What Object-Oriented Programming means • Blueprint → Object analogy • Classes in JavaScript • Constructor methods • Methods inside a class • Basic idea of encapsulation I also added a small assignment to practice creating a Student class. If you're beginning with JavaScript OOP, this should give you a clear starting point. https://lnkd.in/gGzYCZnh Thanks to Nikhil Rathore Hitesh Choudhary Chai Aur Code Piyush Garg Akash Kadlag Jay Kadlag for guidance! #ChaiCode #javascript #webdevelopment #frontenddevelopment #oop #programming #coding #softwaredevelopment #learninpublic
To view or add a comment, sign in
-
🚀 Just published a new blog on JavaScript Operators — the building blocks behind every JS expression! From arithmetic ➕ to logical 🧠 and comparison ⚖️ operators, understanding these fundamentals can seriously level up your coding skills. If you're learning JavaScript or revising core concepts, this guide will help you write cleaner and smarter code. 👉 Read here: https://lnkd.in/df2aq7yc Feedback and support are always appreciated! 💙 #JavaScript #WebDevelopment #Coding #Programming #Frontend #LearnToCode #Developers Hitesh Choudhary
To view or add a comment, sign in
-
-
Just published a new blog: Understanding Objects in JavaScript In this article, I explain: • What objects are and why they are needed • Key–value pair structure • Dot notation vs bracket notation • Updating, adding, and deleting properties • Looping through object keys • Clear comparison between arrays and objects The goal was to keep it beginner-friendly and practical with simple examples. If you are currently learning JavaScript, this will strengthen your fundamentals. https://lnkd.in/gWYSbncC #JavaScript #WebDevelopment #FrontendDevelopment #Programming #Coding #LearnToCode #100DaysOfCode #SoftwareDevelopment #TechLearning
To view or add a comment, sign in
-
Most developers think learning JavaScript means writing long scripts and running them again and again. But Node.js has a hidden playground many beginners ignore — REPL. Think of it like a calculator for JavaScript 🧠 Type a line → see the result instantly. REPL = Read → takes your input Eval → runs the code Print → shows the result Loop → waits for your next command It’s perfect for: ⚡ Testing quick ideas 🐞 Debugging logic 🚀 Learning JavaScript faster Sometimes the fastest way to understand code is simply trying it instantly. 💬 Quick question for developers: Do you actually use the Node.js REPL, or do you jump straight into writing files? #JavaScript #NodeJS #WebDevelopment #Programming #Coding #SoftwareEngineering #Developers #TechLearning #100DaysOfCode #CodingTips #DeveloperCommunity
To view or add a comment, sign in
-
-
🚀 JavaScript Fundamentals Series — Part 9 Once you understand objects, the next step is Object-Oriented Programming. OOP helps structure complex programs using: • Classes • Objects • Encapsulation • Reusable code In this guide I explain how JavaScript implements OOP and how it helps organize applications. Full guide 👇 https://lnkd.in/d37XSu8V #javascript #softwareengineering #webdevelopment
To view or add a comment, sign in
-
🚀 I finally understood Object-Oriented Programming in JavaScript. For a long time, concepts like encapsulation, inheritance, and polymorphism felt confusing. But once I connected them with real-world examples, everything clicked. So I wrote a simple guide to explain: • What Object-Oriented Programming (OOP) really means • How classes and objects work in JavaScript • Encapsulation, Inheritance, and Polymorphism in simple terms If you're learning JavaScript, this might make OOP much easier to understand. Huge thanks to Hitesh Choudhary sir for explaining these concepts so clearly. Your teaching makes complex topics simple. 📖 Read the blog here: https://lnkd.in/gsBTCTp8 If you're learning JavaScript right now: What concept took you the longest to understand?
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