Skip to content

Instantly share code, notes, and snippets.

@danhodge
Last active March 29, 2021 01:05
Show Gist options
  • Save danhodge/6a866620bebef22a06a32e3fad12e690 to your computer and use it in GitHub Desktop.
Save danhodge/6a866620bebef22a06a32e3fad12e690 to your computer and use it in GitHub Desktop.
TypeScript Notes
Install
% npm install -g typescript
Start a new node.js project
% npm init
% npm install typescript -s
Add "tsc" script to package.json
"scripts": {
"tsc": "tsc"
}
% npm run tsc -- --init
Compile
% npm run tsc src/*.ts
Note: if a file/glob is specified, the tsconfig.json file is not consulted: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html
Better to set the rootDir property in tsconfig.json and just run "tsc" to build all files in the project
Run the compiled script
% node script.js
Install node ts types
% npm install @types/node
TS Helper Types
https://gist.github.com/ClickerMonkey/a081b990b9b14215141fb6248cef4dc4
Creating Types from Types
https://www.typescriptlang.org/docs/handbook/2/types-from-types.html
# Typescript Deep Dive
https://basarat.gitbook.io/typescript/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment