Typescript Getting Started

  • Start a project
    npm init
  • install typescript
    • npm install --global typescript

      this will install tsc as a global command.

    • npm install --save-dev typescript

      this will add to package.json and in the code’s node_modules folder but tsc will not be available in the shell

    • to verify install,
      tsc -v

      will give you the version of typescript compiler

  • Add REACT to the project
    npm install react react-dom
    npm install --save-dev @types/react @types/react-dom
  • Note that -i is shorthand for install and -D is shorthand for –save-dev
  • One can use
    npm uninstall (package name)

    to undo an install

  • To run a typescript file directly, not through the browser (i.e. not a web page)
    npm install --global ts-node