DEV Community

Cover image for Why I always "advocate" for typescript 😊
Melbite blogging Platform
Melbite blogging Platform

Posted on • Originally published at melbite.com

Why I always "advocate" for typescript 😊

Hello world, 😊
Did you check out my typescript todo-list-app

Why I prefer typescript

Checking a specific value's type at runtime is the primary function of type guards. This helps the TypeScript compiler, which then uses the information to become more predictive about the types.

I was creating this very platform melbite.com CRUD operations, as usual we have to pass Props when using react. My props consisted of Numbers, Strings and even Boolean and I was running out of time.

How I Fixed it.

Take an example below, you have update user profile component,

<UpdateProfile />
Enter fullscreen mode Exit fullscreen mode

And you want to pass props like username & age, you first have to define your interface props like this,

interface UserData {
username: string,
age: number
}
Enter fullscreen mode Exit fullscreen mode

Then your <UpdateProfile/> component should me looking like this,

const UpdateProfile: FC = (props): JSX.Element => {
  <>

  </>
};
Enter fullscreen mode Exit fullscreen mode

Then pass your props like this,

const UpdateProfile: FC = (props): JSX.Element => {
  <>
    {props.username}
    {props.age}
  </>
};
Enter fullscreen mode Exit fullscreen mode

Recap

Passing props with Javascript might cause unnecessary bugs in your application.
I would advocate every developer to try typescript 😊

You can check out my typescript todo-list-app

And say 👋 if you find this helpful and my site attractive 😊 https://melbite.com

Article originally published at melbite.com/why-i-always-advocate-for-typescript

Top comments (0)