typescript
ㅇ js와 달리 래포론수애 타입을 지정할 수 있어, 한번 지정한 값에는 그 지정한 타입만 사용할 수 있어서 다른 타입을 넣으면 오류가 발생해 잠재적 버그를 런타임 이전에 미리 알고서 처리가 가능
ㅇ PropsTypes대신 사용이 가능하다. 컴포넌트의 props에 타입을 지정해 잘못된 값을 전달시 브라우저 실행 전에 콘솔에서 오류 처리가 가능하다
ㅇ 자동완성이 훨신 편리하게 작용한다. 컴포넌트 작성 시 어떤 props가 필요한지 자동완성으로 볼 수 있다.
typescript 준비
ㅁ 새로운 프로젝트 생성
$ mkdir ts-practice
$ cd ts-practice
$ yarn init -y # 또는 npm init -y
ㅁ typescript 설정파일 생성
$ yarn global add typescript
$ tsc --init
tsconfig.json: typescript 설정파일
ㅇ target: 	컴파일된 코드가 어떤 환경에서 실행할지 정의 화살표함수를 사용하면 es5로 할시 function키워드로 변환 es6면 화살표함수 유지
ㅇ module:	컴파일된 코드가 어떤 모듈 시스템을 사용할지 정의 common으로 하면 export default Sample을 하게 됐을때 컴파일된 코드에서는 exports.default = helloWorld로 변환 es2015면 그래도 유지
ㅇ strict:	모드 타입 체킹 옵션 활성화 esModuleInterap: commonjs모듈 형태로 이루어진 파일을 es2015모듈 형태로 불러올 수 있게함
ㅇ outDir:	컴파일된 파일을 저장되는 경로 지정
tsconfig.json 파일에 outDir설정 추가
{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "strict": true,
    "esModuleInterop": true,
    "outDir": "./dist"
  }
}
$yarn add typescript
  "scripts": {
    "build": "tsc"
  }
tsconfig에서 설정 모음
{
 "compilerOptions": {
  "target": "es5", 
  "module": "commonjs", 
  "allowJs": true, 
  "checkJs": true, 
  "jsx": "preserve", 
  "declaration": true, 
  "outFile": "./", 
  "outDir": "./", 
  "rootDir": "./", 
  "removeComments": true, 
  "strict": true, 
  "noImplicitAny": true, 
  "strictNullChecks": true, 
  "strictFunctionTypes": true, 
  "strictPropertyInitialization": true, 
  "noImplicitThis": true, 
  "alwaysStrict": true, 
  "noUnusedLocals": true, 
  "noUnusedParameters": true, 
  "noImplicitReturns": true, 
  "noFallthroughCasesInSwitch": true, 
 }
}