Skip to content

Fundamental-Academy/ts-basic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 

Repository files navigation

What you need understand before learn TypeScript

  1. JavaScript Basics
  2. Node.js Environment
  3. Package Manager (npm/pnpm)
  4. Familiar working with terminal

How to create a new project with TypeScript:

  1. Create new folder for the project.
  2. In that folder, install TypeScript dependencies:
npm install typescript
  1. Initiate a TypeScript project:
npx tsc --init
  1. Create a new .ts file in the src/ folder via terminal or via UI:
mkdir src
touch src/index.ts
  1. Open the the project in your code editor, and update the package.json file with a new script:
{
  "scripts": {
    "dev": "tsc && node ./build/index.js"
  },
  "devDependencies": {
    ...
  }
}
  1. Configure the tsconfig.json file, add "outDir": "./build" to specify where the compiled JavaScript files should be placed. Also, set "rootDir": "./src" to indicate the root directory of your source files.
{
  "compilerOptions": {
    ...
    "rootDir": "./src",
    ...
    "outDir": "./build",
    ...
  }
}
  1. Try edit the src/index.ts, add several JavaScript code you know for testing the environment.
const myName = "Alfonso";
console.log(myName);
console.log("Hello World");
  1. If you want build and run the project, execute the build script in terminal to compile TypeScript code into JavaScript:
npm run dev
  1. Happy Coding.

About

Learn about basic TypeScript

Resources

Stars

Watchers

Forks