반응형

# TypeScript

## 타입스크립트 시작하기

프로젝트 시작 방법 (라이브러리설치와 TSC)

  • getting-started 폴더 생성 > getting-started 폴더 하위에 index.ts 생성.
function sum(a: number, b: number): number {
    return a + b;
}

sum(10, 20);
  • 컴파일 (Compile) : ts 파일을 js 파일로 변환하는 작업.
  • index.ts 우클릭 > 터미널 열기.
  • node -v : node 설치 여부 확인
  • 라이브러리 설치 (노드 기반 타입스크립트 라이브러리 설치) : npm i typescript -g
  • ts 파일을 js 파일로 컴파일 (입력 시 index.js 생성됨) : tsc index.ts

타입 스크립트 설정 파일

  • getting-started 폴더 하위에 tsconfig.json 생성.
  • tsconfig.json에 key-value 형태로 입력.
{
    "compilerOptions": {
        "allowJs" : true,
        "checkJs" : true,    // @ts-check와 동일한 역할.
        "noImplicitAny" : true	// 타입 명시 옵션(any라도 명시되도록)
    }
}
 

TSConfig Reference - Docs on every TSConfig option

From allowJs to useDefineForClassFields the TSConfig reference includes information about all of the active compiler flags setting up a TypeScript project.

www.typescriptlang.org

타입스크립트 플레이그라운드

 

JavaScript With Syntax For Types.

TypeScript extends JavaScript by adding types to the language. TypeScript speeds up your development experience by catching errors and providing fixes before you even run your code.

www.typescriptlang.org

  • 왼쪽에 타입스크립트 코드 작성 시 오른쪽 화면에서 변환된 결과 확인 가능.

 

 

반응형

+ Recent posts