[typescript]how to build a ts project



This content originally appeared on DEV Community and was authored by bin

first of all, we need to ensure npm and node.js are correctly installed.

mac@MacBook-Pro ~ % node -v
v24.4.1
mac@MacBook-Pro ~ % npm -v
11.4.2

then we need cd into our project dir and create a package.json

mac@MacBook-Pro Work % mkdir ts-demo
mac@MacBook-Pro Work % cd ts-demo 

install ts

mac@MacBook-Pro ts-demo % npm install --save-dev typescript

initialize a config file


mac@MacBook-Pro ts-demo % npx tsc --init


Created a new tsconfig.json                                                     
                                                                             TS 
You can learn more at https://aka.ms/tsconfig

create src/index.ts

const greet = (name: string): string => {
  return `Hello, ${name}!`;
};

console.log(greet("TypeScript on Mac"));

compile it:

mac@MacBook-Pro ts-demo % npx tsc
mac@MacBook-Pro ts-demo % node src/index.js
Hello, TypeScript on Mac!

ok. now the first ts project has been succefully created


This content originally appeared on DEV Community and was authored by bin