Skip to content

Fundamental-Academy/ts-basic-2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

What you need understand before learn TypeScript

  1. JavaScript Basics
  2. Node.js Environment
  3. Package Manager (npm/pnpm)

How to run TypeScript code:

  1. Install tsx dependencies:
npm install --save-dev tsx
  1. Run TypeScript code:
npm run tsx your-file.ts
  1. You also can run TypeScript code directly with tsx:
tsx your-file.ts

How to create a new project with TypeScript:

  1. Install typescript dependencies:
npm install --save-dev typescript
  1. Initiate a TypeScript project:
npx tsc --init
  1. Create a new .ts file in the src/ folder. You can add and edit .ts file in src/ folder.
mkdir src
touch src/index.ts
  1. Update the package.json file with a new script:
{
  "scripts": {
    "dev": "tsc && node ./build/index.js"
  },
  "devDependencies": {
    "typescript": "^5.8.2"
  }
}
  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": {
    ...
    "outDir": "./build",
    ...
    "rootDir": "./src"
    ...
  }
}
  1. Happy Coding. If you want build and run the project, run the build script to compile TypeScript code into JavaScript:
npm run dev

About

Learn to convert JS code to TS code

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published