반응형
# 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라도 명시되도록)
}
}
- 자세한 사항은 래퍼런스 참고. ( https://www.typescriptlang.org/tsconfig )
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
타입스크립트 플레이그라운드
- 타입스크립트 페이지 진입 > 상단에 Playground 클릭하여 진입. ( https://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
- 왼쪽에 타입스크립트 코드 작성 시 오른쪽 화면에서 변환된 결과 확인 가능.
반응형
'인프런 강의 학습 > TypeScript' 카테고리의 다른 글
TypeScript 6일차_타입 별칭 (0) | 2022.03.19 |
---|---|
TypeScript 5일차_인터페이스 (0) | 2022.03.19 |
TypeScript 4일차_할 일 관리 애플리케이션 TS 변환 (0) | 2022.03.18 |
TypeScript 3일차_변수와 함수 타입 정의하기 (0) | 2022.03.16 |
TypeScript 1일차_타입스크립트 개발환경 구성 (0) | 2022.03.14 |