TypeScript code examples for learning purposes 🎓
TypeScript is a strongly typed programming language that builds on JavaScript, giving you better tooling at any scale.
- 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
- Make sure you have Node.js installed
- Install typescript compiler with npm
npm i -D typescript
- Compile typescript files
npx tsc
- Compile typescript files in watch mode
npx tsc --watch
- Create
tsconfig.json
which configure how typescript will behave and compile the files
npx tsc --init
- You can also run directly typescript file with ts-node package
npm i -D ts-node
ts-node index.ts
- If you are going to use
importHelpers
option intsconfig.json
file you are needing to install tslib package
npm i tslib
Type |
---|
number |
string |
bigint |
boolean |
symbol |
null |
undefined |
object |
unknown |
never |
void |
T[] |
[T, T] |
(t: T) => U |
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" |