02 / 08

How does typescript help in writing better code

TypeScript is a superset of JavaScript that adds static types to JavaScript.

Below are the ways in which typescript improves code quality
  1. 1

    Enforcing static typing.

  2. 2

    An editor that supports TypeScript like vscode can deliver “quick fixes” to automatically fix errors, refactorings to easily re-organize code, and useful navigation features for jumping to definitions of a variable or finding all references to a given variable. All of this is built on top of the type-checker and is fully cross-platform.

  3. 3

    Prevents runtime errors by blocking any attempt to access properties that do not exist on an object and return undefined.

  4. 4

    Improved code readability as anyone can understand what type of data is expected in a variable, parameter or value returned by a function

  5. 5

    Error-free code refactoring as any breaking change in function definition will be highlighted.

  6. 6

    Encapsulation and abstraction of the details of different object instances by using types, interfaces and classes.

  7. 7

    Promotes modular code using ES6 or commonJS module system to prevent global scope pollution and naming conflicts.

  8. 8

    Better collaboration among developers working on different interacting parts of the same codebase as it establishes clear contracts for data to be used.