DEV Community

Harry
Harry

Posted on

Should I learn Typescript?

I work with React.js and I was thinking to learn React native. But I have a quick question Should I learn Typescript or should I just go with React Native?

The thing is I can do pretty much everything with Javascript that's why I am little confuse about Typescript. Does it worth giving time or should I just go to mobile development?

Top comments (6)

Collapse
 
lissy93 profile image
Alicia Sykes

YES.
TypeScript is strongly typed, errors will be highlighted at build-time, not run-time, auto-docs and Intellisence is super valuable, TS has additional syntactical features that JS doesn't.
Check out this SO post for more info: stackoverflow.com/a/12694578/979052

Collapse
 
anthonymackie profile image
Harry

Thanks for the post. It really helped me😊

Collapse
 
brense profile image
Rense Bakker

Yes.
Also, typescript == Javascript. The only thing that typescript adds is the option to strongly type your javascript by defining types.

// This is valid javascript AND typescript:
function myFunc(someParameter) {
  return "hello world!"
}

// This is valid typescript with types:
function myFunc(someParameter:string){
  return "hello world!"
}
Enter fullscreen mode Exit fullscreen mode

Because it is strongly typed, typescript will help you to catch errors in your code at build time, instead of runtime and infact if you use visual studio code. It will highlight errors for you before you even attempt to compile your code.

Its also important to note that typescript does type inferrence. Take the code snippet above for example. Typescript will automatically infer the return type of myFunc, you do not have to explicitly define the return type, unless you want to:

function myFunc(someParameter:string):string {
  return 123 // This will produce an error in typescript because we defined the return type needs to be a string
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
anthonymackie profile image
Harry

Thanks man that was really helpful 😊 I guess I'll drive in Typescript then.

Collapse
 
theaccordance profile image
Joe Mainwaring

You should learn Typescript - it's in your benefit so long as you continue to write and maintain JavaScript projects.

Collapse
 
anthonymackie profile image
Harry

I guess typescript is the way to go then.