Skip to content

TypeScript code examples for learning purposes 🎓

License

Notifications You must be signed in to change notification settings

avivharuzi/typescript-examples

Repository files navigation

TypeScript Examples

TypeScript code examples for learning purposes 🎓

What Is TypeScript?

TypeScript is a strongly typed programming language that builds on JavaScript, giving you better tooling at any scale.

TypeScript Advantages

  • TypeScript adds additional syntax to JavaScript to support a tighter integration with your editor. Catch errors early in your editor
  • TypeScript code converts to JavaScript, which runs anywhere JavaScript runs: In a browser, on Node.js or Deno and in your apps
  • TypeScript understands JavaScript and uses type inference to give you great tooling without additional code

How To Use TypeScript?

  1. Make sure you have Node.js installed
  2. Install typescript compiler with npm
npm i -D typescript
  1. Compile typescript files
npx tsc
  1. Compile typescript files in watch mode
npx tsc --watch
  1. Create tsconfig.json which configure how typescript will behave and compile the files
npx tsc --init
  1. You can also run directly typescript file with ts-node package
npm i -D ts-node
ts-node index.ts
  1. If you are going to use importHelpers option in tsconfig.json file you are needing to install tslib package
npm i tslib

TypeScript Common Types

Type
number
string
bigint
boolean
symbol
null
undefined
object
unknown
never
void
T[]
[T, T]
(t: T) => U

TypeScript Predictions

Typescript Predictions
string typeof s === "string"
number typeof n === "number"
bigint typeof m === "bigint"
boolean typeof b === "boolean"
symbol typeof g === "symbol"
undefined typeof undefined === "undefined"
function typeof f === "function"
array Array.isArray(a)
object typeof o === "object"

Useful Resources

JavaScript Documentation

TypeScript Documentation

TypeScript Book

TypeScript Execution

TSConfig Reference

TSConfig Bases Recommendation

TypeScript Types Search

JSON to TypeScript

License

MIT

About

TypeScript code examples for learning purposes 🎓

Topics

Resources

License

Stars

Watchers

Forks