DEV Community

Cover image for 9 tricks that separate a pro Typescript developer from an noob 😎

9 tricks that separate a pro Typescript developer from an noob 😎

Tapajyoti Bose on May 11, 2025

Typescript is a must-know tool if you plan to master web development in 2025, regardless of whether it's for Frontend or Backend (or Fullstack). It...
Collapse
 
kc900201 profile image
KC

I've read from other articles that enums are to be avoided when it comes to data structuring in TypeScript. Lemme know if you have a different opinion. Overall, this is a well summarized reference and thanks for sharing.

Collapse
 
ruppysuppy profile image
Tapajyoti Bose

Yeah as mentioned in the article, enums may break pre-existing data in the DB if new values are introduced (if you don't explicitly mention the mapped values). If you plan to use enums, mapping them to a specific value is a non-negotiable, but you can always use constant objects, mapping the same values.

I personally prefer using enums & haven't run into any issues over the past 4 years apart from the unmapped enums being overwritten

Collapse
 
_ndeyefatoudiop profile image
Ndeye Fatou Diop

Great post! Clear and concise!
However I wouldn’t recommend enums since they have many issues. Best to combine an map with as const and create a type from it 🙏

Collapse
 
ruppysuppy profile image
Tapajyoti Bose • Edited

Check out the response to the other comment

Yeah as mentioned in the article, enums may break pre-existing data in the DB if new values are introduced (if you don't explicitly mention the mapped values). If you plan to use enums, mapping them to a specific value is a non-negotiable, but you can always use constant objects, mapping the same values.

I personally prefer using enums & haven't run into any issues over the past 4 years apart from the unmapped enums being overwritten

Collapse
 
_ndeyefatoudiop profile image
Ndeye Fatou Diop

So that is not the only issue with enums. The other thing with enums is that you cannot pass a string (which is the same value as the enum): which is super annoying.

enum Direction {
  Up = "up",
  Down = "down"
}

function move(direction: Direction) {
  console.log(direction);
}

move("down") // <- TS will complain here
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
ruppysuppy profile image
Tapajyoti Bose • Edited

You can write your own helper to convert the string to enum:

function toDirection(value: string): Direction {
  if (!Object.values(Direction).includes(value as Direction)) {
    throw Error("Invalid direction")
  }
  return value as Direction;
}
Enter fullscreen mode Exit fullscreen mode

Personally use zod to tackle the transformations & handle all Document/DTO schemas

Collapse
 
deividas_strole profile image
Deividas Strole

Fantastic article! It really highlights how powerful TypeScript is for catching errors early, improving code readability, and making large-scale projects easier to manage. Once you get used to it, it's hard to go back to plain JavaScript.

Collapse
 
hexshift profile image
HexShift

Nice! The tips on type inference and literal types are particularly handy, and I appreciate how you've broken things down into easily digestible bits that both newcomers and seasoned devs can benefit from. Shows just how much you can optimize your code with just a few key tricks. One suggestion I’d throw out there is a quick mention of using TypeScript with async/await patterns and sometimes the type inference can be a bit tricky there, so a little guidance would be useful.

Collapse
 
ruppysuppy profile image
Tapajyoti Bose

The only difference is when using async, the return type gets wrapped by a Promise

const asyncFn = async () => 0; // type AsyncFn = () => Promise<number>
Enter fullscreen mode Exit fullscreen mode

When you await, the Promise gets unwrapped & you can use it as a regular value

const func = async () => {
  const result = await asyncFn(); // type Result = number
}
Enter fullscreen mode Exit fullscreen mode

Everything else mentioned in the article still holds true regardless whether you are using Promises or not

Collapse
 
georgelakeg profile image
GeorgeLake

This was such a fun and insightful read! I love how the tips cut through the fluff and really emphasize habits that elevate code quality—like mastering utility types, using discriminated unions, and embracing type inference wisely. It's kind of like when you switch from watching random content to curated lists on PlayPelis APK—suddenly, the experience feels smarter and more intentional. Have you found one of these TypeScript tricks that gave you that big "aha!" moment in your own projects?

Collapse
 
ruppysuppy profile image
Tapajyoti Bose

Definitely literal types & using type guards - it insanely simplified handling types

Collapse
 
nevodavid profile image
Nevo David

Insane, this makes TypeScript feel way less scary tbh. The index signature vs Record part always trips me up lol.

Collapse
 
ekalkutin profile image
Evgenii Kalkutin

Are you even sleeping lol? I see you in almost every post. or you're bot haha?

Collapse
 
gajananpp profile image
Gajanan Patil

Nice article ! When I was learning Typescript, these Cheat Sheets on their website really helped me.

Collapse
 
nidomiro profile image
Niclas

Good list, although I do not use the TS-enum but other alternate structures for it.

Collapse
 
george_gardiakos_c9a7c2b7 profile image
George Gardiakos

This awesome. I use some of these but not all. Thank you!

Collapse
 
werliton profile image
Werliton Silva

I like it

Collapse
 
nathan_tarbert profile image
Nathan Tarbert

no joke, posts like this are what got me through my first typescript repo

Collapse
 
cmacu profile image
Stasi Vladimirov

You missed generics and discriminative types

Collapse
 
ruppysuppy profile image
Tapajyoti Bose • Edited

Re-read the article - generic are there & even though I don't explicitly mention the term discriminative types, it's touched upon in the Type guard section