[TypesSript] Install, Setting

parkjh9370·2022년 5월 26일
0

🔎 install

brew install typescript : 설치
tsc : 설치 확인

tsc -h : 가능한 모든 옵션

tsc 파일명 : 타입스크립트 -> 자바스크립트 파일로 변환
tsc 파일명 -w : 변경사항 감지해서 자바스크립트로 컴파일

node install -g ts-node
ts-node 파일명 : 해당 파일 ts로 실행

🔎 Basic Setting

tsc --init : TypeScript 세팅 (tsconfig.json 생성)

tsconfig.json

"target": "es6", 	/* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"module": "ES2015",	/* Specify what module code is generated. */
"rootDir": "./src",		/* Specify the root folder within your source files. */

"outDir": "./build",	/* Specify an output folder for all emitted files. */
"removeComments": true,		/* Disable emitting comments. */
// 컴파일 에러 발생 시 더 이상 컴파일을 진행하지 않도록 설정 (추가 설정
"noEmitOnError": true,

"esModuleInterop": true,	/* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */

"forceConsistentCasingInFileNames": true,	/* Ensure that casing is correct in imports. */

"strict": true,		/* Enable all strict type-checking options. */

"noUnusedLocals": true,		/* Enable error reporting when a local variables aren't read. */
"noUnusedParameters": true,		/* Raise an error when a function parameter isn't read */

"noImplicitReturns": true,		/* Enable error reporting for codepaths that do not explicitly return in a function. */
"noFallthroughCasesInSwitch": true,		/* Enable error reporting for fallthrough cases in switch statements. */
"noUncheckedIndexedAccess": true,		/* Include 'undefined' in index signature results */

"skipLibCheck": true		/* Skip type checking all .d.ts files. */
{
 "compilerOptions": {

  "target": "es5", // 'es3', 'es5', 'es2015', 'es2016', 'es2017','es2018', 'esnext' 가능
  "module": "commonjs", //무슨 import 문법 쓸건지 'commonjs', 'amd', 'es2015', 'esnext'
  "allowJs": true, // js 파일들 ts에서 import해서 쓸 수 있는지 
  "checkJs": true, // 일반 js 파일에서도 에러체크 여부 
  "jsx": "preserve", // tsx 파일을 jsx로 어떻게 컴파일할 것인지 'preserve', 'react-native', 'react'
  "declaration": true, //컴파일시 .d.ts 파일도 자동으로 함께생성 (현재쓰는 모든 타입이 정의된 파일)
  "outFile": "./", //모든 ts파일을 js파일 하나로 컴파일해줌 (module이 none, amd, system일 때만 가능)
  "outDir": "./", //js파일 아웃풋 경로바꾸기
  "rootDir": "./", //루트경로 바꾸기 (js 파일 아웃풋 경로에 영향줌)
  "removeComments": true, //컴파일시 주석제거 

  "strict": true, //strict 관련, noimplicit 어쩌구 관련 모드 전부 켜기
  "noImplicitAny": true, //any타입 금지 여부
  "strictNullChecks": true, //null, undefined 타입에 이상한 짓 할시 에러내기 
  "strictFunctionTypes": true, //함수파라미터 타입체크 강하게 
  "strictPropertyInitialization": true, //class constructor 작성시 타입체크 강하게
  "noImplicitThis": true, //this 키워드가 any 타입일 경우 에러내기
  "alwaysStrict": true, //자바스크립트 "use strict" 모드 켜기

  "noUnusedLocals": true, //쓰지않는 지역변수 있으면 에러내기
  "noUnusedParameters": true, //쓰지않는 파라미터 있으면 에러내기
  "noImplicitReturns": true, //함수에서 return 빼먹으면 에러내기 
  "noFallthroughCasesInSwitch": true, //switch문 이상하면 에러내기 
 }
}

0개의 댓글