[udemy강의 typescript 기본 설정] tsconfig.json
{
"compilerOptions": {
/* Basic Options */
"target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"lib": [
"dom",
"es6",
"dom.iterable",
"scripthost"
] /* Specify library files to be included in the compilation. */,
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
"sourceMap": true /* Generates corresponding '.map' file. */,
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./dist" /* Redirect output structure to the directory. */,
"rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
// "composite": true, /* Enable project compilation */
"removeComments": true /* Do not emit comments to output. */,
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
"noEmitOnError": true,
/* Strict Type-Checking Options */
"strict": true /* Enable all strict type-checking options. */,
// "noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
"noUnusedLocals": true /* Report errors on unused locals. */,
"noUnusedParameters": true /* Report errors on unused parameters. */,
"noImplicitReturns": true /* Report error when not all code paths in function return a value. */,
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
},
"exclude": [
"node_modules" // would be the default
]
}
1. target 옵션 : 어떤 자바스크립트 버전을 대상으로 코드를 컴파일 할 것인지(기본옵션)
2. lib 옵션 : dom으로 작업을 수행하는 항목들(기본 객체, 기능, 타입스크립트 노드를 지정) (ex: document.querySelector를 사용할 수 있는 이유) lib 설정이 되어있지 않지만 기본값이 동작함 아무것도 설정하지 않은 채 lib를 주석해제하면 console.log 나 document를 인식하지 못함
ctrl+space로 자동완성을 확인할 수 있음
"lib": [ "DOM", "ES6", "DOM.Iterable", "ScriptHost" ]
자바스크립트 핵심기능 사용 가능한 lib설정
(“target“: “es6”와 같은 설정임)
3. sourceMap 옵션 : 디버깅과 개발에 유용하다. 값을 참으로 하고 커멘드를 실행하면 .js.map파일이 생성됨. 해당 파일은 최신브라우저와 개발자 도구간 다리. ts 파일도 디버깅을 위해 sources 탭에 나타나게 된다.
4. outDir 옵션 : 설정하면 컴파일 후 생성된 JS파일이 저장되는 위치를 알려주는 역할을 한다. (파일을 정렬할 때 유용한 기능) ts파일 저장된 폴더의 구조를 그대로 가져오는 역할도 하여준다. (하위 폴더 구조도 가져옴)
5. rootDir 옵션 : 설정하고 파일이 저장되는 폴더에서 구체적으로 설정하여 타입스크립트 컴파일러가 폴더에서 보이지 않도록 할 수 있다. (include옵션과 다른점 : src폴더 확인 + 설정한 프로젝트 구조가 dist 폴더에서 유지되는지 확인)
6. removeComments 옵션 : .ts파일의 모든 주석이 컴파일된 자바스크립트 파일에서 제거됨
7. noEmitOnError : default 값은 false. 자바스크립트 파일 생성에 문제가 없고 에러가 발생하는 경우 이 값을 true로 설정하면 문제가 되는 파일이 다시 생성되지 않는다. 한 부분에 문제가 있으면 모든 파일이 생성되지 않음
*********Strict type-checking options****************
8. strict : true옵션으로 strict 유형의 검사 옵션을 사용할 수 있다. strictOptions의 모든 옵션들을 true로 설정한 것과 같다.
*********Additional checks **************
9. noUnusedLocals : 사용하지 않은 로컬 변수가 있을 때 에러 나게 한다.
10. nounusedParameters : 사용하지 않은 매개변수가 있을 때 에러 나게 한다.
11. noImplicitReturns: 반환하지 않는 함수가 있는 경우 에러 나게 한다. 아무것도 반환하지 않는 경우 return 으로라도 따로 적어줘야 에러나지 않게 된다.
*********Module Resolution Options**************
12. esModuleInterop 속성이 위의 코드 처럼 true로 설정될 경우, ES6 모듈 사양을 준수하여 CommonJS 모듈을 가져올 수 있게됨
13. exclude 옵션 : 컴파일에서 제외할 파일