This content originally appeared on DEV Community and was authored by mashayeakh islam
Hey everyone! I’m Masayeakh, a Full stack Dev from Bangladesh who’s learning TypeScript to level up my skills.
Last week, I started my TypeScript journey — and wow, it’s been an exciting ride so far! From type safety to cleaner code, I can already see why so many developers love it.
In this post, I’ll share 5 simple but powerful lessons I learned in my first week of TypeScript. If you’re starting out like me, this might help you avoid confusion and learn faster 🚀
💡 1. TypeScript Catches Errors Before You Run the Code
In JavaScript, many bugs show up only when you run your code.
But in TypeScript, errors appear while you’re writing.
let age: number = "25"; // ❌ Type error: Type 'string' is not assignable to type 'number'
> It’s like having a super strict but helpful teacher who doesn’t let you make silly mistakes.
💬 2. Defining Function Types Keeps Your Code Clean
You can define what type of data a function expects and what it returns.
function add(a: number, b: number): number {
return a + b;
}
> If you accidentally return a string or forget a parameter, TypeScript immediately warns you.
It makes functions predictable — which is great for big projects.
🧱 3. Objects and Type Aliases Make Life Easier
Instead of writing object types again and again, you can use type aliases.
type User = {
name: string;
age: number;
email?: string; // optional property; email will be added if used otherwise blank;
};
const user1: User = { name: "Masayeakh", age: 25 };
> This makes code look cleaner, especially when building apps with many components.
🔒 4. Readonly Properties Prevent Unwanted Changes
If you don’t want something to be modified, just make it readonly.
type Config = {
readonly apiUrl: string;
};
const config: Config = { apiUrl: "https://api.example.com" };
config.apiUrl = "https://newurl.com"; // ❌ Error
> This is small but super useful in team projects where mistakes happen.
🔗 5. Union Types Are a Game-Changer
Union types let a variable hold more than one type.
function getId(id: number | string) {
return id;
}
getId(123);
getId("abc");
> They’re great when your data can come in multiple forms (like user IDs or API responses).
🎯 Final Thoughts
My first week with TypeScript taught me one thing — type safety = peace of mind.
It doesn’t just catch bugs early; it helps me write more confident, organized code.
Next, I’ll dive into interfaces, generics, and TypeScript with React — can’t wait to share that journey too!
If you’re learning TypeScript as well, let’s connect and grow together 💬
🧠 About Me
I’m a Full Stack Developer learning AI-driven TypeScript, Next.js, and modern web technologies.**
I love building projects, sharing what I learn, and connecting with global devs.
Let’s grow together — both in code and life 🌍💻
This content originally appeared on DEV Community and was authored by mashayeakh islam
mashayeakh islam | Sciencx (2025-10-27T05:14:20+00:00) 5 Things I Learned in My First Week of TypeScript. Retrieved from https://www.scien.cx/2025/10/27/5-things-i-learned-in-my-first-week-of-typescript/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.