자바스크립트를 활성화 해주세요

d029 Codewars Typescript 문제 풀기 위한 Webstorm 설정방법

 ·  ☕ 2 min read

typescript로 codewars에 도전해 볼까요? 환경부터 만들어야겠죠?

nodejs 설치

nodejs가 설치되어있지 않은 경우에 한합니다. 역시 scoop으로 설치합니다. node버전을 바로 설치하는 것도 방법이지만, nvm (node version manager)를 통해서 관리하는 것이 버전이 바뀌었을 때 대응이 쉽기 때문에, 먼저 nvm을 설치합니다.

scoop install nvm
nvm install latest

결과

C:\Users\Administrator>nvm install latest
Downloading node.js version 14.13.1 (64-bit)...
Complete
Creating C:\Users\Administrator\scoop\persist\nvm\nodejs\temp

Downloading npm version 6.14.8... Complete
Installing npm v6.14.8...

Installation complete. If you want to use this version, type

nvm use 14.13.1

C:\Users\Administrator>nvm use 14.13.1
Now using node v14.13.1 (64-bit)

C:\Users\Administrator>node --version
v14.13.1

프로젝트 디렉토리

다음은 프로젝트 디렉토리를 만들고 typescript 모듈을 설치합니다.

mkdir temp3; cd temp3
npm init -y
npm install --save typescript
npx tsc --init

결과

C:\Users\Administrator\temp3>npm init -y
Wrote to C:\Users\Administrator\temp3\package.json:

{
  "name": "temp3",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

C:\Users\Administrator\temp3>npm install --save typescript
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN temp3@1.0.0 No description
npm WARN temp3@1.0.0 No repository field.

+ typescript@4.0.3
added 1 package from 1 contributor and audited 1 package in 2.084s
found 0 vulnerabilities

C:\Users\Administrator\temp3>npx tsc --init
message TS6071: Successfully created a tsconfig.json file.

샘플 코드 작성

여기서부터는 powershell을 사용하겠습니다. 이유는 단순히 커맨드라인에서 파일을 만드는 것이 쉽기 때문입니다.

1
2
3
4
5
6
7
8
9
mkdir src
@"
// js/main.ts
export const summation = (num:number)=> {
  console.log('hello world')
}
summation(1);
"@ > src/main.ts
npx tsc src/main.ts

결과

~/temp3 is 📦 v1.0.0 via ⬢ v14.13.1 took 3s
❯ node src/main.js
Hello !

webstorm 시작

webstorm .

다음과 같은 화면이 나옵니다. 실행 단축키는 alt-shift-f10 입니다.

d029_codewars_typescript.png

추가적으로 해줄 작업이 있다면, 옵션에서 소스코드가 바뀌었을 때 자동으로 재컴파일하게 하는 정도입니다.

d029_webstorm_typescript.png

기타

  • vscode로도 설정은 가능합니다만, 여러가지 vscode의 설정이 필요한 만큼, 전문 ide를 가지고 있다면 활용하는 것이 좋습니다.
  • visual studio도 가능합니다만, 너무 무겁기 때문에 큰 부담이 됩니다.

jetbrains IDE는 무료로도 사용할 수 있기 때문에, 경험해 보시고 구입하는 것이 좋습니다.

레퍼런스

공유하기

tkim
글쓴이
tkim
Software Engineer