남과 같이 해선 남 이상이 될 수 없다.

TypeScript

2021/06/17 TypeScript

맨동 2021. 6. 17. 17:05
728x90

tsconfig 최상위 프로퍼티

 

compileOnSave: true/false (default false)

파일 변경 후 저장하면 자동 컴파일을 해주는 옵션입니다. 에디터마다 안될 수도 있습니다.

VS2015 with TypeScript 1.8.4 이상

// tsconfig.json
{
   "compileOnSave": true
}

 

extends : "경로"

특정 타입스크립트 설정 파일에서 다른 타입스크립트 설정의 내용을 가져와 추가할 수 있는 속성입니다.

TypeScipt 2.1 이상

// config/base.json
{
  "compilerOptions": {
    "noImplicitAny": true
  }
}
// tsconfig.json
{
  "extends": "./config/base"
}

 

files, include, exclude

TypeScipt 2.0이상

  • 셋다 설정이 없으면 , 전부다 컴파일 

 files

  • 상대 혹은 절대 경로의 리스트 배열.
  • 파일별 부분 컴파일이 된다.
  • exclude 보다 쎕니다. (exclude가 해놓아도 files 에 있으면 컴파일 실행된다는 뜻)
  • 특정 폴더를 exclude가 있어도 컴파일 된다.

include, exclude

  • glob 패턴 (마치 .gitignore)
  • include
    • exclude 보다 약하다.
      • 같은걸 사용하면 , .ts / .tsx / .d.ts 만 include (allowJS)
  • exclude
    • 설정 안하면 4가지 (node_modules, bower_components, - jspm_packages, )를 default 로 제외한다 .
    •  항상 제외합니다 . (include 에 있어도 )

 

compileOptions

-typeRoots 와 @types 라이브러리

TypeScipt 2.0이상

타입스크립트 설정 파일은 기본적으로 node_modules를 제외하지만 써드 파티 라이브러리의 타입을 정의해놓는 @types 폴더는 컴파일에 포함합니다.

  • 이전 버전에서는 사용하지 못한다.
  • 아무 설정을 안하면 ?
    • node_modules/@types 라는 모든 경로를 찾아서 사용
  • typeRoots 를 사용하면 ?
    • 배열 안에 들어있는 경로들 아래서만 가져옵니다 .
  • types 를 사용하면 ?
    • 패키지 이름입니다.
    • 배열 안의 모듈 혹은 ./node_modules/@types/ 안의 모듈 이름에서 찾아옵니다 .
    • [] 빈 배열을 넣는다는건 이 시스템을 이용하지 않겠다는 것입니다 .
      • 블루베리 플젝에서는 types 를 사용한다 .
  • typeRoots 와 types 를 같이 사용하지 않습니다 .
// compiileOptions : type
{
  "type": "object",
  "description": "Instructs the TypeScript compiler how to compile .ts files.",
  "properties": {
    "typeRoots": {
      "description":
        "Specify list of directories for type definition files to be included. Requires TypeScript version 2.0 or later.",
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "types": {
      "description":
        "Type declaration files to be included in compilation. Requires TypeScript version 2.0 or later.",
      "type": "array",
      "items": {
        "type": "string"
      }
    }
  }
}

 

compileOptions

-taget과 lib

target

타입스크립트 파일을 컴파일 했을 때 빌드 디렉토리에 생성되는 자바스크립트의 버전을 의미합니다. 기본 값인 es3부터 es5, es6 등 가장 최신 버전인 esnext까지 있습니다.

// tsconfig.json
{
  "target": "esnext"
}

lib

  • 기본 type definition 라이브러리를 어떤 것을 사용할 것이냐
  • 잘 정의하지 않으면 빨간줄이 계속 생긴다 .
  • lib 를 지정하지 않을 때 ,
    • target 이 ‘es3’ 이고, 디폴트로 lib.d.ts 를 사용합니다.
    • target 이 ‘es5’ 이면 , 디폴트로 dom, es5, scripthost 를 사용합니다 .
    • target 이 ‘es6’ 이면, 디폴트로 dom, es6, dom.iterable, scripthost 를 사용합니다.
    • es5 이후에는 문법별 쪼개서도 설정 가능하다 .
  • ​lib 를 지정하면 그 lib 배열로만 라이브러리를 사용하니다.
    • ​ 빈 [] => ‘no definition found 어쩌구’
// tsconfig.json
{
  "lib": ["es2015", "dom", "dom.iterable"]
}

 

compileOptions

-outDir, outFile, rootDir

  • 파일을 다 모아서 하나의 컴파일된 하나의 파일로 모으고 싶을 때 outFile을 사용
  • 소스디렉토리에 그대로 똑같이 구조를 컴파일된 상태로 옮길 때 outDir 를 사용
{
  "type": "object",
  "description": "Instructs the TypeScript compiler how to compile .ts files.",
  "properties": {
    "outFile": {
      "description": "Concatenate and emit output to single file.",
      "type": "string"
    },
    "outDir": {
      "description": "Redirect output structure to the directory.",
      "type": "string"
    },
    "rootDir": {
      "description":
        "Specifies the root directory of input files. Use to control the output directory structure with --outDir.",
      "type": "string"
    }
  }
}

 

compileOptions

-strict (무조건 지정해서 사용)

모든 엄격한 타입-체킹 옵션을 활성화 하는 옵션입니다.

"strict": true, /* 모든 엄격한 타입-체킹 옵션 활성화 여부 */
  // "noImplicitAny": true, /* 명시적이지 않게 any 타입을 사용하여, 표현식과 선언에 사용하면 에러 발생 */
  // "strictNullChecks": true, /* 엄격한 null 확인 여부 */
  // "strictFunctionTypes": true, /* 함수 타입에 대한 엄격한 확인 여부 */
  // "strictBindCallApply": true, /* 함수에 엄격한 'bind', 'call' 그리고 'apply' 메소드 사용 여부 */
  // "strictPropertyInitialization": true, /* 정의되지 않은 클래스의 속성이 생성자에게 초기화 되었는지 확인(strictNullChecks를 사용 필수) */
  // "noImplicitThis": true, /* 명시적이지 않게 any 타입을 사용하여, this 표현식에 사용하면 에러 발생 */
  // "alwaysStrict": true, /* strict mode로 분석하고 모든 소스 파일에 "use strict"를 추가할 지 여부 */

 

tsconfig.json 컴파일 옵션 정리

{
  "compilerOptions": {
    /* https://aka.ms/tsconfig.json 를 방문하면 해당 파일에 대한 더 많은 정보를 얻을 수 있습니다. */
    // 옵션은 아래와 같은 형식으로 구성되어 있습니다.
    // "모듈 키": 모듈 값 /* 설명: 사용가능 옵션 (설명이 "~ 여부"인 경우 'true', 'false') */
    /* 기본 옵션 */
    // "incremental": true, /* 증분 컴파일 설정 여부 */
    "target": "es5", /* 사용할 특정 ECMAScript 버전 설정: 'ES3' (기본), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 혹은 'ESNEXT'. */
    "module": "commonjs", /* 모듈을 위한 코드 생성 설정: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
    // "lib": [], /* 컴파일에 포함될 라이브러리 파일 목록 */
    // "allowJs": true, /* 자바스크립트 파일 컴파일 허용 여부 */
    // "checkJs": true, /* .js 파일의 오류 검사 여부 */
    // "jsx": "preserve", /* JSX 코드 생성 설정: 'preserve', 'react-native', 혹은 'react'. */
    // "declaration": true, /* '.d.ts' 파일 생성 여부. */
    // "declarationMap": true, /* 각 '.d.ts' 파일의 소스맵 생성 여부. */
    // "sourceMap": true, /* '.map' 파일 생성 여부. */
    // "outFile": "./", /* 단일 파일로 합쳐서 출력합니다. */
    // "outDir": "./", /* 해당 디렉토리로 결과 구조를 보냅니다. */
    // "rootDir": "./", /* 입력 파일의 루트 디렉토리(rootDir) 설정으로 --outDir로 결과 디렉토리 구조를 조작할 때 사용됩니다. */
    // "composite": true, /* 프로젝트 컴파일 여부 */
    // "tsBuildInfoFile": "./", /* 증분 컴파일 정보를 저장할 파일 */
    // "removeComments": true, /* 주석 삭제 여부 */
    // "noEmit": true, /* 결과 파일 내보낼지 여부 */
    // "importHelpers": true, /* 'tslib'에서 헬퍼를 가져올 지 여부 */
    // "downlevelIteration": true, /* 타겟이 'ES5', 'ES3'일 때에도 'for-of', spread 그리고 destructuring 문법 모두 지원 */
    // "isolatedModules": true, /* 각 파일을 분리된 모듈로 트랜스파일 ('ts.transpileModule'과 비슷합니다). */
    /* 엄격한 타입-확인 옵션 */
    "strict": true, /* 모든 엄격한 타입-체킹 옵션 활성화 여부 */
    // "noImplicitAny": true, /* 'any' 타입으로 구현된 표현식 혹은 정의 에러처리 여부 */
    // "strictNullChecks": true, /* 엄격한 null 확인 여부 */
    // "strictFunctionTypes": true, /* 함수 타입에 대한 엄격한 확인 여부 */
    // "strictBindCallApply": true, /* 함수에 엄격한 'bind', 'call' 그리고 'apply' 메소드 사용 여부 */
    // "strictPropertyInitialization": true, /* 클래스의 값 초기화에 엄격한 확인 여부 */
    // "noImplicitThis": true, /* 'any' 타입으로 구현된 'this' 표현식 에러처리 여부 */
    // "alwaysStrict": true, /* strict mode로 분석하고 모든 소스 파일에 "use strict"를 추가할 지 여부 */
    /* 추가적인 확인 */
    // "noUnusedLocals": true, /* 사용되지 않은 지역 변수에 대한 에러보고 여부 */
    // "noUnusedParameters": true, /* 사용되지 않은 파라미터에 대한 에러보고 여부 */
    // "noImplicitReturns": true, /* 함수에서 코드의 모든 경로가 값을 반환하지 않을 시 에러보고 여부 */
    // "noFallthroughCasesInSwitch": true, /* switch문에서 fallthrough 케이스에 대한 에러보고 여부 */
    /* 모듈 해석 옵션 */
    // "moduleResolution": "node", /* 모듈 해석 방법 설정: 'node' (Node.js) 혹은 'classic' (TypeScript pre-1.6). */
    // "baseUrl": "./", /* non-absolute한 모듈 이름을 처리할 기준 디렉토리 */
    // "paths": {}, /* 'baseUrl'를 기준으로 불러올 모듈의 위치를 재지정하는 엔트리 시리즈 */
    // "rootDirs": [], /* 결합된 컨텐츠가 런타임에서의 프로젝트 구조를 나타내는 루트 폴더들의 목록 */
    // "typeRoots": [], /* 타입 정의를 포함할 폴더 목록, 설정 안 할 시 기본적으로 ./node_modules/@types로 설정 */
    // "types": [], /* 컴파일중 포함될 타입 정의 파일 목록 */
    // "allowSyntheticDefaultImports": true, /* default export이 아닌 모듈에서도 default import가 가능하게 할 지 여부, 해당 설정은 코드 추출에 영향은 주지 않고, 타입확인에만 영향을 줍니다. */
    "esModuleInterop": true, /* 모든 imports에 대한 namespace 생성을 통해 CommonJS와 ES Modules 간의 상호 운용성이 생기게할 지 여부, 'allowSyntheticDefaultImports'를 암시적으로 승인합니다. */
    // "preserveSymlinks": true, /* symlik의 실제 경로를 처리하지 않을 지 여부 */
    // "allowUmdGlobalAccess": true, /* UMD 전역을 모듈에서 접근할 수 있는 지 여부 */
    /* 소스 맵 옵션 */
    // "sourceRoot": "", /* 소스 위치 대신 디버거가 알아야 할 TypeScript 파일이 위치할 곳 */
    // "mapRoot": "", /* 생성된 위치 대신 디버거가 알아야 할 맵 파일이 위치할 곳 */
    // "inlineSourceMap": true, /* 분리된 파일을 가지고 있는 대신, 단일 파일을 소스 맵과 가지고 있을 지 여부 */
    // "inlineSources": true, /* 소스맵과 나란히 소스를 단일 파일로 내보낼 지 여부, '--inlineSourceMap' 혹은 '--sourceMap'가 설정되어 있어야 한다. */
    /* 실험적 옵션 */
    // "experimentalDecorators": true, /* ES7의 decorators에 대한 실험적 지원 여부 */
    // "emitDecoratorMetadata": true, /* decorator를 위한 타입 메타데이터를 내보내는 것에 대한 실험적 지원 여부 */
    /* 추가적 옵션 */
    "skipLibCheck": true, /* 정의 파일의 타입 확인을 건너 뛸 지 여부 */
    "forceConsistentCasingInFileNames": true /* 같은 파일에 대한 일관되지 않은 참조를 허용하지 않을 지 여부 */
  }
}
728x90

'TypeScript' 카테고리의 다른 글

2021/06/21 TypeScript  (0) 2021.06.21
2021/06/19 TypeScript  (0) 2021.06.19
2021/06/15 타입스크립트  (0) 2021.06.15
2021/06/11 타입스크립트  (0) 2021.06.11
2021/06/10 타입스크립트  (0) 2021.06.10