Skip to content

Instantly share code, notes, and snippets.

@tnn4
Created September 14, 2022 23:32
Show Gist options
  • Select an option

  • Save tnn4/6e251c290bb2161bf6bed8c423e72c35 to your computer and use it in GitHub Desktop.

Select an option

Save tnn4/6e251c290bb2161bf6bed8c423e72c35 to your computer and use it in GitHub Desktop.
typescript notes

TypeScript setup

typscript is a classed superset of javascript and has

  • classes
  • modules
  • interfaces

typescript.ts -> tsc -> javascript.js -> browser

tsc is the typescript compiler and is a node package installed with npm (node package manager)

tsc transpiles .ts to .js

  • transpile : also called source-to-source compilers are a subset of compilers that take source code file and translate it to another source code file in another language

vs

  • compiler: take source code and turn it into some other language(usually) machine code, notice that this says nothing specifically about source to source because it is more general

node.tsc

e.g. Helloworld.ts -> tsc -> Helloworld.js -> node

  • tsc Helloworld.ts
  • node Helloworld.js

VSCode has TypeScript language support but does not come with the compiler.

You need to use npm to install the compiler tsc npm install -g typescript

You can also install locally npm install --save-dev typescript

Make a tsconfig.json to define project settings

e.g.

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "sourceMap": true
  }
}

Tip: The tsc compiler does not detect the presence of a jsconfig.json file automatically. Use the –p argument to make tsc use your jsconfig.json file, e.g. tsc -p jsconfig.json.

Typescript tutorial

Compiling Typescript

transpile vs compile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment