TypeScript Won’t Save Your Product: The Case for Clean Code Practices

You think using TypeScript is gonna keep your product alive, definitely NOT 😂 Here's why!

People are obsessed with TypeScript, and I don't say it's wrong.

But when it's used incorrectly (without proper clean code principles), even it'll cause a disaster instead of saving us.

Let me give you an example:

The Problem

const getLogs = (
  userId: string,
  from?: Date,
  to?: Date,
  sort?: Map<string, number>,
  limit?: number,
  lastLogId?: string
) => {};

This function might look fine at first glance, but it's not.

Now think about the consumer:

How will they know the order of all those optional parameters?

Having this many parameters in a function not only makes it harder to maintain but also makes it prone to errors.

The Solution

Here's a cleaner approach:

interface LogsOptions {
  interval?: {
    from?: Date;
    to?: Date;
  };
  pagination?: {
    limit?: number;
    lastLogId?: string;
  };
  sort?: Map<string, number>;
}

const getLogs = (userId: string, options?: LogsOptions) => {};

This approach is:
✅ Cleaner
✅ Easier to maintain
✅ Less prone to errors

Consumers can immediately understand what parameters are available without guessing.

Moral of the story

TypeScript alone won't save your product. Regardless of the language or framework you use, clean code principles play a vital role in your product's longevity.

Frameworks and languages come and go, but the fundamentals stay the same.

💬 What practices do you follow to keep your product alive? Share your thoughts in the comments!

Cheers,
Navayuvan Subramanian

0
Subscribe to my newsletter

Read articles from Navayuvan Subramanian directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Navayuvan Subramanian
Navayuvan Subramanian

👋 Hey there! I’m a Full Stack Developer with 3+ years of experience building top-notch web and mobile apps. I’m here to help you craft the best app for your product using tech stacks like MERN, Flutter, React Native, Django, and more. 🚀 Currently on a mission to build an app that ensures you never forget a crucial task (believe me, it’s a total game changer!). 🚀💡