Code with Typescript will be useful

Code with Typescript will be useful

·

2 min read

Working for a solo project or mixed project will often have bugs, one of the typical debugging is misplacing the data type and it will spend developers' time identifying before making any execution. To make every data set has its standard, Typescript was introduced in October 2012 by Microsoft internally to tackle the issues faster. Subsequently, it grows its popularity in the programming ecosystem and many corporations require it as a basic requirement while recruiting new developer staff.

What is Typescript?

Typescript (TS) is an open-source programming language and it is considered the superset of Javascript (JS). Typescript compiles the code written to Javascript at the end of the project environment run. The main reason why Typescript is being used by many developers is that it provides static code writing.

Bugs in programming files are inevitable and identifying which part has a bug will be more challenging especially deadline is coming soon.

To illustrate, a function that has 2 arguments (ie. salary and bonus) to count employment salary.

function getSalaryWithBonus(salary, bonus){
  return salary * bonus
}

Without any specification of argument type, it will go wrong, especially for junior developer type like below

const salary = getSalaryWithBonus(3000,'0')
// Result is 30000

The final result will have 30000 without detecting any error. The company will therefore lose money for each salary processed.

With Typescript, it prevents any people developer including senior one to make a silly mistake and it can automatically detect number is not assigned accordingly.

function getSalaryWithBonus (salary: number, bonus:number){
  return salary * bonus
}
const salary = getSalaryWithBonus(3000,'0')
// Error

Typescript Benefits

  • It identifies bugs early while Javascript at the runtime
  • It can be used for discretionary static compose
  • It can run in any program
  • It is predictable with the intended data type
  • It helps developer organize their code
  • it has fast refactoring without changing its behavior

Typescript Downside

  • It requires many efforts to code and not many developers want to put effort to learn an additional language
  • It is not fully aligned with Javascript, especially in High Order Function, Composition, and Generic Higher Keys.

Did you find this article valuable?

Support Bill Wee by becoming a sponsor. Any amount is appreciated!