Coder Social home page Coder Social logo

typescript-must-know's Introduction

typescript-must-know

Setup

Setup is from https://basarat.gitbooks.io/

  1. Setup a Node.js project package.json. Quick one : npm init -y

  2. Add TypeScript (npm install typescript --save-dev)

  3. Add node.d.ts (npm install @types/node --save-dev)

  4. Init a tsconfig.json for TypeScript options (npx tsc --init)

  5. Make sure you have compilerOptions.module:commonjs in your tsconfig.json

Bonus: Live compile + run

Live compile part is from https://basarat.gitbooks.io/

  • Add ts-node which we will use for live compile + run in node (npm install ts-node --save-dev)
  • Add nodemon which will invoke ts-node whenever a file is changed (npm install nodemon --save-dev)

Now just add a script target to your package.json based on your application entry e.g. assuming its index.ts:

  "scripts": {
    "start": "npm run build:live",
    "build:live": "nodemon --exec ./node_modules/.bin/ts-node -- ./index.ts"
  },

So you can now run npm start and as you edit index.ts:

  • nodemon reruns its command (ts-node)
  • ts-node transpiles automatically picking up tsconfig.json and the installed typescript version,
  • ts-node runs the output javascript through Node.js.

Build JS file

$ npm run build

Reference

typescript-must-know's People

Contributors

wahengchang avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.