🚀 Mastering TypeScript Basics (The Smart Way!) When I started learning TypeScript, a few concepts really helped me write cleaner and safer code. Here’s a quick breakdown 👇 🔹 Tuples – Fixed-length arrays with defined types. 🔹 Enums – Define a set of named constants. 🔹 Any – Turns off TypeScript type checking (use carefully!). 🔹 Unknown – Similar to any, but safer. You must check the type before using it. 🔹 Void – When a function doesn’t return anything. 🔹 Null / Undefined – Represent “nothing” or “not assigned yet.” 🔹 Never – Used for functions that never return (like infinite loops or errors). TypeScript might look strict at first, but once you understand these basics — it actually saves you from countless bugs 💪 #TypeScript #JavaScript #WebDevelopment #FrontendDevelopment #FullStackDevelopment #Programming #SoftwareDevelopment #CodeNewbie #LearnToCode #CodingJourney #DeveloperCommunity #100DaysOfCode #WebDev #TypeSafety #TechLearning #JS #DevLife #CleanCode #SoftwareEngineer #WebAppDevelopment #ModernJavaScript #CodingLife #Developer #TechJourney #TypeScriptTips #ProgrammingLife #TypeScriptDeveloper
Mastering TypeScript Basics: Tuples, Enums, Any, Unknown, Void, Null, Undefined, Never
More Relevant Posts
-
🚀 Master TypeScript in 2025: From Zero to Hero! Just published a comprehensive TypeScript guide covering everything you need to know: ✅ Basic Types & Interfaces ✅ Generics & Advanced Types ✅ OOP with Classes ✅ Real-world Patterns ✅ TypeScript with React & Express ✅ Best Practices & Common Pitfalls Whether you're a beginner or looking to level up your TypeScript skills, this 4500+ word guide has you covered with practical examples and code snippets. Perfect for: 👨💻 JavaScript developers wanting to learn TypeScript 📈 Teams looking to improve code quality 🎯 Anyone building scalable applications Read the full guide here: https://lnkd.in/e5XgCxAH What's your biggest challenge with TypeScript? Drop a comment below! 👇 #TypeScript #WebDevelopment #JavaScript #Programming #SoftwareDevelopment #Coding #TechTutorial #LearnToCode
To view or add a comment, sign in
-
-
In my last article, I talked about the 'Parameters<T>' utility type in TypeScript which is used to get the types of the parameters of a function. After extracting function parameters using Parameters<T>, the next logical question is - "What if we want to extract the return type of a function?" That’s exactly what 'ReturnType<T>' helps us do. 'ReturnType<T>' takes a function type and gives us the type of the value it returns. This is incredibly useful when you’re reusing the result of a function elsewhere or you’re wrapping or composing functions, or maybe you want to avoid manually updating types if the function’s return type changes. Just like 'Parameters<T>,' it pairs perfectly with 'typeof.' You can pass an existing function directly, and TypeScript will automatically infer the return type for you. But things get interesting when async functions enter the picture. An 'async' function will return a 'Promise,' which means 'ReturnType<typeof fn>' gives you something like 'Promise<X>' instead of just 'X'. To handle that, TypeScript has 'Awaited<T>,' a utility type that unwraps the resolved type from a Promise. So, if you combine both, you get the actual value type returned by an async function. In other words, 'Awaited<ReturnType<typeof fn>>' gives you the true resolved type. This combination becomes super useful when writing helpers or working with async workflows where you want full type safety. Together, 'ReturnType' and 'Awaited' give you a clean, readable, and type-safe way to infer what a function, synchronous or asynchronous, really returns. #TypeScript #Programming #WebDevelopment #Coding #JavaScript
To view or add a comment, sign in
-
-
There’s a subtle behavior in TypeScript that surprises many developers. A variable can start with the type 'any,' but then its type can change (or 'evolve') as you assign values to it. This is called 'Evolving any.' This happens when you declare a variable without a type and without an initial value. When you do this, TypeScript doesn’t know what the variable should be. So it temporarily treats it as 'any.' But as soon as you assign a value, TypeScript refines the type based on that value, and it continues to update that type as you assign new values later. In other words, the type 'evolves' to match the values being assigned. This is different from explicitly setting the type as 'any'. When you explicitly set the type of a variable as 'any,' the variable always remains 'any.' TypeScript won't do any type checking on it, and you lose type safety completely. But when you declare a variable without a type and without an initial value, it starts as 'any,' but each assignment changes the inferred type. So, 'evolving any' still preserves type checking, while an explicit 'any' does not. Arrays evolve as well. If you start with an empty array, then TypeScript infers it as 'any[]' initially. But once you start adding values, the array type evolves accordingly. After pushing numbers, it becomes 'number[].' After later pushing a string, it becomes '(number | string)[].' TypeScript does this because it is designed to support gradual typing. Sometimes you genuinely don’t know the variable value at the moment of declaration, and 'evolving any' allows type inference to 'catch up' later. #TypeScript #JavaScript #Coding #Programming #WebDevelopment
To view or add a comment, sign in
-
-
I often see this common misunderstanding: Strong types != static types. - Rust has strong and static types. - JavaScript has weak and dynamic types. - TypeScript has strong and dynamic types. You COULD argue that TypeScript is static since it enforces types at compile time, but that's not really a useful distinction. JavaScript doesn't get any less dynamic when compiled by TypeScript. TypeScript just statically analyzes a dynamic runtime model. It's simpler and arguably more accurate to call it a dynamically typed language.
To view or add a comment, sign in
-
I think this confused some people. Let's try again: When people talk about TypeScript, they're typically referring to the ENTIRE thing, meaning scripts AND annotations together. const something: Something = new Something(); Someone will tell you "that's TypeScript," but they won't say "That's JavaScript with a TypeScript annotation." The latter is what we ACTUALLY mean when we say "TypeScript is statically typed." But Type annotations by themselves are not useful as a programming language. That would be like trying to program logical conditions using HTML. All the parts that make code actually do something are JavaScript. But none of that is very practical for conversation, so we talk about TypeScript like it replaces JavaScript entirely and becomes a new standalone language... but when you start omitting details, it starts getting into dangerous territory. We have to pick and choose which details are meaningful, and which ones are safe to discard. I'm picking on the industry at large for a bad decision here. If we talk about TypeScript as a standalone language, then we have to consider both its compiler and its runtime together. 90% of it is just JavaScript, 10% is a static analyzer for dynamic types. I find it odd that we'd look at that last 10%, drop half of it, and then say "that's what 100% of this is." The industry will try to tell you TypeScript is statically typed. I will tell you that's misleading; questionable at best. What's funny is TypeScript's own website never once says "statically typed" and I believe that's intentional for this reason.
I often see this common misunderstanding: Strong types != static types. - Rust has strong and static types. - JavaScript has weak and dynamic types. - TypeScript has strong and dynamic types. You COULD argue that TypeScript is static since it enforces types at compile time, but that's not really a useful distinction. JavaScript doesn't get any less dynamic when compiled by TypeScript. TypeScript just statically analyzes a dynamic runtime model. It's simpler and arguably more accurate to call it a dynamically typed language.
To view or add a comment, sign in
-
Ever used ANY in TypeScript just to silence that red error? 😅 I’ve been there. At first, ANY felt like a lifesaver — no type errors, no complaints. Until one day, a number turned into a string, a string into an object, and my code broke at the worst possible time. 😬 Then I discovered UNKNOWN. Unlike ANY, it doesn’t trust blindly — it asks questions first. It’s like a teammate who double-checks before merging your PR — a little strict, but saves you from disaster. 😉 What I learned: any = quick peace, later chaos. unknown = small checks, big safety. TypeScript isn’t limiting JavaScript — it makes it smarter, safer, and cleaner. Now, I let TypeScript guide me, because sometimes the best debugging tool is the type warning you didn’t ignore. #TypeScript #JavaScript #WebDevelopment #FrontendDevelopment #CodingTips #CleanCode #Programming #CodeBetter #SoftwareDevelopment
To view or add a comment, sign in
-
Conquering the JavaScript Roadmap 🚀 The journey of a thousand lines begins with a single comment.Today, we're not just writing code; we're building the foundation for innovation This detailed roadmap covers everything essential from understanding why JavaScript is important and how to run it in the browser using the <script> tag, to mastering core variables like var, let, and const with Sheryians Coding School and our one and only Harsh Vandana Sharma #JavaScript #CodingJourney #WebDevelopment #CodeLife #LearnToCode #FrontendDevelopment #JSFundamentals
To view or add a comment, sign in
-
-
🚀 Day 29 of #100DaysOfDev 🧠 The Core of Understanding — Explained Through TypeScript The key to truly understanding any concept lies in your ability to articulate it in your own words and build a logical flow between related ideas. That’s what strengthens your fundamentals — forming a clear story that connects the concepts together. Here’s a simple example using TypeScript 👇 TypeScript is a superset of JavaScript that adds type safety to your code. Type safety is achieved by assigning types to variables, functions, and other programming elements — ensuring values behave as expected. Types in TypeScript can be: Primitives (string, number, boolean, etc.) Custom types and interfaces Union and intersection types Enums, and more Assigning a type simply tells TypeScript that a value must be of a specific type — and it will throw an error if not. Meanwhile, type assertion tells TypeScript that you already know the exact type of a value and want it to trust your claim. Understanding these fundamentals helps you not just write code — but think in code. 💡 #100DaysOfDev #TypeScript #JavaScript #WebDevelopment #CodingJourney #FrontendDevelopment #LearnInPublic
To view or add a comment, sign in
-
🚀 JavaScript Scope Understanding scope is one of the keys to writing clean, bug-free JavaScript. 👉 Global Scope: Accessible everywhere 👉 Function Scope: Accessible only inside the function 👉 Block Scope (let, const): Accessible only inside {} 👉 Local Scope: Exists only where it's declared Mastering scope = fewer errors + cleaner code. 💡 Happy coding! ⚡ #JavaScript #JS #WebDevelopment #Frontend #Coding #Programmer #Developer #SoftwareEngineer #LearningToCode #TechLearning #100DaysOfCode #CodeNewbie #WebDeveloper #TechEducation #CleanCode #ProgrammingBasics #SoftwareDevelopment #ES6 #FullStack #TechCommunity #Debugging #WomenWhoCode #Developers #LearnJavaScript #NaveenCodes
To view or add a comment, sign in
-
Starting a new project in pure JavaScript vs. starting it in TypeScript. JS: Feels fast, then you hit a scaling issue. 😬 TS: Feels like 5 minutes of setup, then you have a static safety net for the next 5 years. 🛡️ That initial investment in type definitions saves so much headache down the road. Future you will thank you for those strict flags. #TypeScriptAdoption #Coding #SoftwareDevelopment
To view or add a comment, sign in
Explore related topics
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