node.js 초기화
npm init
@types/node 설치
npm i @types/node
package.json 파일에 dependencies로 @types/node가 추가된다.타입스크립트 컴파일러 설치
npm install typescript -g
tsctsc -vsrc/index.ts 생성
console.log("Hello TypeScript");
const a: number = 1;
컴파일 명령어 입력
tsc src/index.ts
src/index.js 파일이 생성된다.컴파일 된 js 파일 실행
node src/index.js
Hello TypeScript 출력tsx 설치
npm i -g tsx
실행
tsx src/index.ts
Hello TypeScript 출력undici-types 오류만약, 컴파일 시 다음과 같은 오류가 발생한다면?
Cannot find module 'undici-types'.
{
"compilerOptions": {
"skipLibCheck": true
}
}
tsconfig.json 파일 내 skipLibCheck 설정 추가하기
"skipLibCheck": true 옵션이 해결해 주는 이유
.d.ts) 간의 충돌 무시