why should move from javascipt to typescript

what is typescript

A typed superset of JavaScript Developed by Microsoft it Compiles to JavaScript for either Browsers or Node there are Three parts: Language, Language Service and Compiler.
When we read typescript, it consists of type and script so what is type.
Type as we know there are tow type of type variable
Fist type is Primitive Types
Which the value of type it is Six primitive types in JS:
Null -undefined -boolean-number-string-symbol(it add in 2015)
The second type is object or reference it maybe object or function or variable pointer to oner object.

As we know Type Conversion
As with many dynamically-typed languages, things are converted “as needed”
30 + 7; //37
‘37’ + 7; //”37”
‘37’ - 7;// 30
(+ '37’) ;//37
(+ false) ;//0
Some it generates some error
Sometimes JavaScript does unintuitive things to convert primitive types

Why is important to learn typescript.

  • It provides machinimas to autocomplete feather or property when we write the code.
  • It helps use to find problem when we write code immediately rather make compile in other language as java or it make compiler the find that compile error.
  • Move some common errors from runtime to compile time
  • Great documentation for fellow developers
  • Those clever abstractions you’re so excited about are now safer to use
  • Modern JavaScript runtimes are written in typed languages
  • Add some farther as Enum, union

some code in ts

const login = (username: string, password: string): User => {
!/ do something !*
} 

Some time we need to convert it from type to another by keyword “as”

document.querySelector('input#name_field') as HTMLInputElement;
  "green",
  () => {}
]);

const objectCar: { name: String, number: Number}={
     name:"dsdsds",
     number:10,
}

If any error in the shape the compile it will unhappy it put red line in the location when it not happy

     name:"dsdsds",
     number:"dsddds",
}

number must show message Type ‘string’ is not assignable to type ‘Number’

#javascript #typescript #node-js #js #reactjs

why should move from javascipt to typescript
3.95 GEEK