โ ๋ณต์ก์ฑ์ ํต์ ํ๋ ๊ฒ์ด ์ปดํจํฐ ํ๋ก๊ทธ๋๋ฐ์ ๊ธฐ์ด๋ค. โ
- Brian Kernigan
์ปดํจํฐ ๊ณผํ์, ์ต์ด๋ก C์ธ์ด ํ๋ก๊ทธ๋๋ฐ์ด๋ ์ฑ ์ ์ ์

ํ์ ์คํฌ๋ฆฝํธ ์ปดํ์ผ ์ค์
tsconfig.json์ ํ์ ์คํฌ๋ฆฝํธ๋ฅผ ์๋ฐ์คํฌ๋ฆฝํธ๋ก ๋ณํ ์ํค๋ ์ปดํ์ผ ์ค์ ์ ํ๊บผ๋ฒ์ ์ ์ ํด๋๋ ํ์ผ์ด๋ผ๊ณ ๋ณด๋ฉด ๋๋ค. ํ๋ก์ ํธ๋ฅผ ์ปดํ์ผ ํ๋๋ฐ ํ์ํ ๋ฃจํธ ํ์ผ, ์ปดํ์ผ๋ฌ ์ต์ ๋ฑ์ ์์ธํ ์ค์ ํ ์ ์๋ค.
๋ณดํต tsconfig.json ํ์ผ์ TypeScript ํ๋ก์ ํธ์ ๋ฃจํธ ๋๋ ํ ๋ฆฌ(Root Directory)์ ์์น๋๋ค. ๊ทธ๋์ tsconfig.json ํ์ผ์ด ํ๋ก์ ํธ์ ์๋ค๋ฉด vscode๋ ์ฐ๋ฆฌ๊ฐ ํ์ ์คํฌ๋ฆฝํธ๋ก ๊ฐ๋ฐํ๋ค๋ ๊ฒ์ ์ธ์ํ๊ฒ ๋๋ ๊ฒ์ด๋ค.
tsconfig์์ ์ต์
๋ค์ ๋ฏธ๋ฆฌ ์ ์ํด ๋์ผ๋ฉด, ๋์ด์ ์ปดํ์ผ ํ ๋ ๋ช
๋ น์ด์ ์ผ์ผํ ๋์ ํ์ผ์ด๋ ์ต์
์ ์ง์ ํ์ง ์์๋ ๋๋ค. ๊ทธ๋์ tsc ๋ ts-node ๋ช
๋ น์ด๋ฅผ ๊ทธ๋ฅ ์คํํ๊ฒ ๋๋ฉด, ํ์ฌ ํด๋์ ์๋ tsconfig ์ค์ ๋ด์ฉ์ ๊ธฐ์ค์ผ๋ก ํ๋ก์ ํธ์์ ์์ค๋ค์ ๋ณํ ์์
(์ปดํ์ผ)์ ์งํํ๊ฒ ๋๋ค. ๋ง์ฝ ํ์ฌ ํด๋์ 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
TypeScript ํ๊ธ ๋ฌธ์
TypeScript ํ๊ธ ๋ฒ์ญ ๋ฌธ์์ ๋๋ค
typescript-kr.github.io
tsconfig ์์ฑ
๋ค์ ๋ช ๋ น์ด๋ฅผ ์คํํ๋ฉด ๋ฏธ๋ฆฌ ์์ฑ๋ tsconfig.json ํ์ผ์ ์๋์ผ๋ก ๋ง๋ค์ด์ค๋ค. ํ์ผ์ ์ด์ด๋ณด๋ฉด ์ฌ์ง์์ ๋ณด๋ค ์ํผ ๋ฌด์ํ ๋ง์ ์ต์ ๋ค์ด ์๋๊ฑธ ๋ณผ ์ ์๋ค.
> tsc --init

tsconfig ์ ์ญ ์์ฑ
tsconfig ์ ์ญ ์์ฑ์ด๋, ํ์ผ์ ์ต์์์ ์์นํ๊ณ ์๋ ์์ฑ๋ค์ ์ผ์ปซ๋๋ค.
{
// TypeScript ์ปดํ์ผ๋ฌ์ ์ต์
๋ค์ ์ง์ ํ๋ ์์ฑ
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"strict": true,
"sourceMap": true
// ... ๋ฌด์ํ ๋ง์ ์์ฑ๋ค
},
// ์ปดํ์ผํ ํ์ผ๋ค์ ๊ฐ๋ณ ๋ชฉ๋ก์ ์ง์ ํ๋ ์์ฑ
"files": ["src/main.ts", "src/utils.ts"],
// ์ปดํ์ผํ ํ์ผ๋ค์ ์ง์ ํ๋ ์์ฑ (์์ผ๋ ์นด๋ ํจํด์ผ๋ก ๋ฌถ์ด ํํ)
"include": [ "src/**/*.ts" ],
// ์ปดํ์ผ ๋์์์ ์ ์ธํ ํ์ผ๋ค์ ์ง์ ํ๋ ์์ฑ
"exclude": [ "node_modules", "**/*.test.ts" ],
// ๋ค๋ฅธ tsconfig.json ํ์ผ์ ์์๋ฐ์์ ์ค์ ์ ์ฌ์ฌ์ฉํ ์ ์๊ฒ ํด์ฃผ๋ ์์ฑ
"extends": "./configs/base.json",
// ์ฌ๋ฌ ๊ฐ์ ํ์ ํ๋ก์ ํธ๋ก ๊ตฌ์ฑ๋ ํ๋ก์ ํธ์ ์์กด ๊ด๊ณ๋ฅผ ์ง์ ํ๋ ์์ฑ
"references": [
{ "path": "./subproject1" },
{ "path": "./subproject2" }
],
// ํ์
์ต๋(type acquisition)๊ณผ ๊ด๋ จ๋ ์ต์
๋ค์ ์ง์ ํ๋ ์์ฑ
"typeAcquisition": {
"enable": true,
"include": ["jquery"],
"exclude": ["react"]
},
// watch ๋ชจ๋์ ๊ด๋ จ๋ ์ต์
๋ค์ ์ง์ ํ๋ ์์ฑ
"watchOptions": {
"watchFile": "useFsEvents",
"watchDirectory": "useFsEvents",
"fallbackPolling": "dynamicPriority"
}
}
์ ๋ง ๋ง์ ์ ์ญ ์์ฑ๋ค์ด ์์ง๋ง, ์ด์ค์์ ์ฃผ๋ก ์ฐ์ด๋ ๋ค์ฏ๊ฐ์ ์์ฑ์ผ๋ก๋ compilerOptions, files, include, exclude, extends ์ ๋๊ฐ ์๋ค.
files
ํ๋ก์ ํธ์์ ์ปดํ์ผํ ํ์ผ๋ค์ ๋ชฉ๋ก์ ๋ช ์์ ์ผ๋ก ์ง์ ํ๋ ์์ฑ์ด๋ค.
files ์์ฑ์ ๋ฐ์์ ๋ฐฐ์ธ exclude๋ณด๋ค ์ฐ์ ์์๊ฐ ๋๋ค. ๋ง์ผ ์ด ์์ฑ์ด ์๋ต๋๋ฉด include์ exclude ์์ฑ์ผ๋ก ์ปดํ์ผ ๋์์ ๊ฒฐ์ ํ๋ค.
{
"files": [ // ํ์ผ ํ์ฅ์๊น์ง ์ ํํ ์์ฑํด์ค์ผ ํ๋ค
"src/main.ts",
"src/utils.ts",
"src/types.d.ts"
]
}
extends
extends๋ ๋ค๋ฅธ tsconfig.json ํ์ผ์ ์ค์ ๋ค์ ๊ฐ์ ธ์ ์ฌ์ฌ์ฉํ ์ ์๊ฒ ํด์ฃผ๋ ์ต์ ์ด๋ค. ๋ณดํต extends ์์ฑ์ tsconfig.json ํ์ผ์ ์ต์์์ ์์นํ๋ค.
์๋ฅผ๋ค์ด config/base.json ํ์ผ์ ์์ฑ ์ค์ ์ ํ tsconfig.json ํ์ผ์ ํฌ๋งท์ด ๋ง์ผ๋ฉด baseํ์ผ์ ์ค์ ์ ์์ ๋ฐ๊ฒ ๋๋ค.
// config/base.json
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true
}
}
{
"extends": "./configs/base",
"compilerOptions": {
"strictNullChecks": false
},
"files": [
"src/main.ts",
"src/utils.ts",
"src/types.d.ts"
]
}
include
include ์์ฑ์ files ์์ฑ๊ณผ ๊ฐ์ด ํ๋ก์ ํธ์์ ์ปดํ์ผํ ํ์ผ๋ค์ ์ง์ ํ๋ ์์ฑ์ด์ง๋ง, ์์ผ๋ ์นด๋ ํจํด์ผ๋ก ์ง์ ํ๋ค๋ ์ ์์ ์ฐจ์ด๊ฐ ์๋ค. ๋ํ include๋ files ์์ฑ๊ณผ๋ ๋ฌ๋ฆฌ exclude๋ณด๋ค ์ฝํด include์ ๋ช ์๋์ด ์์ด๋ exclude์๋ ๋ช ์๋์ด ์์ผ๋ฉด ์ ์ธ ๋๊ฒ ๋๋ค.
{
"compilerOptions": {
...
},
"include": [
"src/*.ts", // src ๋๋ ํ ๋ฆฌ์ ์๋ ๋ชจ๋ .ts ํ์ผ
"dist/test?.ts" // dist ๋๋ ํ ๋ฆฌ์ ์๋ test1.ts, test2.ts , test3.ts ..๋ฑ์ ์ผ์น
"test/**/*.spec.ts" // test ๋๋ ํ ๋ฆฌ์ ๊ทธ ํ์ ๋๋ ํ ๋ฆฌ์ ์๋ ๋ชจ๋ .spec.ts ํ์ผ
]
}
์์ผ๋ ์นด๋ ํจํด์ด๋ tsconfig.json ํ์ผ์์ include๋ exclude ์์ฑ์ ์ฌ์ฉํ ์ ์๋ ํ์ผ์ด๋ ๋๋ ํ ๋ฆฌ๋ฅผ ๊ทธ๋ฃนํํ์ฌ ์ผ์น์ํค๋ ๊ธฐํธ๋ผ๊ณ ๋ณด๋ฉด ๋๋ค.
- * : ํด๋น ๋๋ ํ ๋ฆฌ์ ์๋ ๋ชจ๋ ํ์ผ
- ? : ํด๋น ๋๋ ํ ๋ฆฌ์ ์๋ ํ์ผ๋ค์ ์ด๋ฆ ์ค ํ ๊ธ์๋ผ๋ ํฌํจํ๋ฉด ํด๋น
- ** : ํด๋น ๋๋ ํ ๋ฆฌ์ ํ์ ๋๋ ํ ๋ฆฌ์ ๋ชจ๋ ํ์ผ์ ํฌํจ
exclude
exclude ์์ฑ์ ํ๋ก์ ํธ์์ ์ปดํ์ผ ๋์์์ ์ ์ธํ ํ์ผ๋ค์ ์์ผ๋์นด๋ ํจํด์ผ๋ก ์ง์ ํ๋ ์์ฑ์ด๋ค. ์ฆ, include์ ๋ฐ๋ ๋ฒ์ ์ด๋ผ ๋ณด๋ฉด ๋๋ค.
{
"compilerOptions": {
...
},
"exclude": [
"node_modules", // node_modules ๋๋ ํ ๋ฆฌ๋ฅผ ์ ์ธ
"**/*.test.ts" // ๋ชจ๋ .test.ts ํ์ผ์ ์ ์ธ
]
}
compilerOptions
์ปดํ์ผ ๋์ ํ์ผ๋ค์ ์ด๋ป๊ฒ ๋ณํํ ์ง ์ธ์ธํ ์ ํ๋ ์ต์ ์ด๋ค. ์ ๋ง ๋ง์ ์ต์ ๋ค์ด ์๊ณ , ์ด๋ค์ค ์ ์ฉ๋๋ ์ต์ ๋ค์ ๋ฐ๋ก ๋ค์ ์น์ ์์ ์์ธํ ๋ค๋ฃฌ๋ค.
{
"compilerOptions": {
/* ๊ธฐ๋ณธ ์ต์
* ------------------------------------------------------------------------------------------------------------------------------------------------ */
"incremental": true, /* ์ฆ๋ถ ์ปดํ์ผ ํ์ฑํ */
"target": "es5", /* ECMAScript ๋ชฉํ ๋ฒ์ ์ค์ : 'ES3'(๊ธฐ๋ณธ), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "esnext", /* ์์ฑ๋ ๋ชจ๋ ์ฝ๋ ์ค์ : 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
"lib": ["dom", "dom.iterable", "esnext"], /* ์ปดํ์ผ ๊ณผ์ ์ ์ฌ์ฉ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ํ์ผ ์ค์ */
"allowJs": true, /* JavaScript ํ์ผ ์ปดํ์ผ ํ์ฉ */
"checkJs": true, /* .js ํ์ผ ์ค๋ฅ ๋ฆฌํฌํธ ์ค์ */
"jsx": "react", /* ์์ฑ๋ JSX ์ฝ๋ ์ค์ : 'preserve', 'react-native', or 'react'. */
"declaration": true, /* '.d.ts' ํ์ผ ์์ฑ ์ค์ */
"declarationMap": true, /* ํด๋นํ๋ ๊ฐ '.d.ts'ํ์ผ์ ๋ํ ์์ค ๋งต ์์ฑ */
"sourceMap": true, /* ์์ค๋งต '.map' ํ์ผ ์์ฑ ์ค์ */
"outFile": "./", /* ๋ณต์ ํ์ผ์ ๋ฌถ์ด ํ๋์ ํ์ผ๋ก ์ถ๋ ฅ ์ค์ */
"outDir": "./dist", /* ์ถ๋ ฅ๋ ๋๋ ํ ๋ฆฌ ์ค์ */
"rootDir": "./", /* ์
๋ ฅ ํ์ผ๋ค์ ๋ฃจํธ ๋๋ ํ ๋ฆฌ ์ค์ . --outDir ์ต์
์ ์ฌ์ฉํด ์ถ๋ ฅ ๋๋ ํ ๋ฆฌ ์ค์ ์ด ๊ฐ๋ฅ */
"composite": true, /* ํ๋ก์ ํธ ์ปดํ์ผ ํ์ฑํ */
"tsBuildInfoFile": "./", /* ์ฆ๋ถ ์ปดํ์ผ ์ ๋ณด๋ฅผ ์ ์ฅํ ํ์ผ ์ง์ */
"removeComments": true, /* ์ถ๋ ฅ ์, ์ฃผ์ ์ ๊ฑฐ ์ค์ */
"noEmit": true, /* ์ถ๋ ฅ ๋ฐฉ์ถ(emit) ์ ๋ฌด ์ค์ */
"importHelpers": true, /* 'tslib'๋ก๋ถํฐ ํฌํผ๋ฅผ ํธ์ถํ ์ง ์ค์ */
"downlevelIteration": true, /* 'ES5' ํน์ 'ES3' ํ๊ฒ ์ค์ ์ Iterables '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, /* ์๊ฒฉ๋ชจ๋์์ ๊ตฌ๋ฌธ ๋ถ์ ํ, ๊ฐ ์์ค ํ์ผ์ "use strict" ์ฝ๋๋ฅผ ์ถ๋ ฅ */
/* ์ถ๊ฐ ๊ฒ์ฌ ์ต์
* ------------------------------------------------------------------------------------------------------------------------------------------------ */
"noUnusedLocals": true, /* ์ฌ์ฉ๋์ง ์์ ๋ก์ปฌ์ด ์์ ๊ฒฝ์ฐ, ์ค๋ฅ๋ก ๋ณด๊ณ */
"noUnusedParameters": true, /* ์ฌ์ฉ๋์ง ์์ ๋งค๊ฐ๋ณ์๊ฐ ์์ ๊ฒฝ์ฐ, ์ค๋ฅ๋ก ๋ณด๊ณ */
"noImplicitReturns": true, /* ํจ์๊ฐ ๊ฐ์ ๋ฐํํ์ง ์์ ๊ฒฝ์ฐ, ์ค๋ฅ๋ก ๋ณด๊ณ */
"noFallthroughCasesInSwitch": true, /* switch ๋ฌธ ์ค๋ฅ ์ ํ์ ๋ํ ์ค๋ฅ ๋ณด๊ณ */
"noUncheckedIndexedAccess": true, /* ์ธ๋ฑ์ค ์๊ทธ๋์ฒ ๊ฒฐ๊ณผ์ 'undefined' ํฌํจ */
/* ๋ชจ๋ ๋ถ์ ์ต์
* ------------------------------------------------------------------------------------------------------------------------------------------------ */
"moduleResolution": "node", /* ๋ชจ๋ ๋ถ์ ๋ฐฉ๋ฒ ์ค์ : 'node' (Node.js) ๋๋ 'classic' (TypeScript pre-1.6). */
"baseUrl": "./", /* ์ ๋ ๊ฒฝ๋ก ๋ชจ๋์ด ์๋, ๋ชจ๋์ด ๊ธฐ๋ณธ์ ์ผ๋ก ์์นํ ๋๋ ํ ๋ฆฌ ์ค์ (์: './modules-name') */
"paths": {}, /* 'baseUrl'์ ๊ธฐ์ค์ผ๋ก ์๋ ์์น๋ก ๊ฐ์ ธ์ค๊ธฐ๋ฅผ ๋ค์ ๋งคํํ๋ ํญ๋ชฉ ์ค์ */
"rootDirs": [], /* ๋ฐํ์ ์ ํ๋ก์ ํธ ๊ตฌ์กฐ๋ฅผ ๋ํ๋ด๋ ๋กํธ ๋๋ ํ ๋ฆฌ ๋ชฉ๋ก */
"typeRoots": [], /* ์ ํ ์ ์๋ฅผ ํฌํจํ ๋๋ ํ ๋ฆฌ ๋ชฉ๋ก */
"types": [], /* ์ปดํ์ผ ์ ํฌํจ๋ ์ ํ ์ ์ธ ํ์ผ ์
๋ ฅ */
"allowSyntheticDefaultImports": true, /* ๊ธฐ๋ณธ ์ถ๋ ฅ(default export)์ด ์๋ ๋ชจ๋๋ก๋ถํฐ ๊ธฐ๋ณธ ํธ์ถ์ ํ์ฉ (์ด ์ฝ๋๋ ๋จ์ง ์ ํ ๊ฒ์ฌ๋ง ์ํ) */
"esModuleInterop": true, /* ๋ชจ๋ ๊ฐ์ ธ์ค๊ธฐ์ ๋ํ ๋ค์์คํ์ด์ค ๊ฐ์ฒด ์์ฑ์ ํตํด CommonJS์ ES ๋ชจ๋ ๊ฐ์ ์ํธ ์ด์ฉ์ฑ์ ์ ๊ณต. 'allowSyntheticDefaultImports' ์์ */
"preserveSymlinks": true, /* symlinks ์ค์ ๊ฒฝ๋ก๋ก ๊ฒฐ์ ํ์ง ์์ */
"allowUmdGlobalAccess": true, /* ๋ชจ๋์์ UMD ๊ธ๋ก๋ฒ์ ์ ๊ทผ ํ์ฉ */
/* ์์ค๋งต ์ต์
* ------------------------------------------------------------------------------------------------------------------------------------------------ */
"sourceRoot": "./", /* ๋๋ฒ๊ฑฐ(debugger)๊ฐ ์์ค ์์น ๋์ TypeScript ํ์ผ์ ์ฐพ์ ์์น ์ค์ */
"mapRoot": "./", /* ๋๋ฒ๊ฑฐ๊ฐ ์์ฑ๋ ์์น ๋์ ๋งต ํ์ผ์ ์ฐพ์ ์์น ์ค์ */
"inlineSourceMap": true, /* ํ๋์ ์ธ๋ผ์ธ ์์ค๋งต์ ๋ด๋ณด๋ด๋๋ก ์ค์ */
"inlineSources": true, /* ํ๋์ ํ์ผ ์์ ์์ค์ ์์ค ์ฝ๋๋ฅผ ํจ๊ป ๋ด๋ณด๋ด๋๋ก ์ค์ . '--inlineSourceMap' ๋๋ '--sourceMap' ์ค์ ์ด ํ์ */
/* ์คํ์ ์ธ ๊ธฐ๋ฅ ์ต์
* ------------------------------------------------------------------------------------------------------------------------------------------------ */
"experimentalDecorators": true, /* ES7 ๋ฐ์ฝ๋ ์ดํฐ(decorators) ์คํ ๊ธฐ๋ฅ ์ง์ ์ค์ */
"emitDecoratorMetadata": true, /* ๋ฐ์ฝ๋ ์ดํฐ๋ฅผ ์ํ ์ ํ ๋ฉํ๋ฐ์ดํฐ ๋ฐฉ์ถ ์คํ ๊ธฐ๋ฅ ์ง์ ์ค์ */
/* ๊ณ ๊ธ ์ต์
* ------------------------------------------------------------------------------------------------------------------------------------------------ */
"skipLibCheck": true, /* ์ ์ธ ํ์ผ ์ ํ ๊ฒ์ฌ ์คํต */
"forceConsistentCasingInFileNames": true /* ๋์ผํ ํ์ผ์ ๋ํ ์ผ๊ด๋์ง ์์ ์ผ์ด์ค ์ฐธ์กฐ๋ฅผ ํ์ฉํ์ง ์์ */
}
}
compilerOptions ์ต์ ์ค๋ช
์์์ ๋ดค๋ฏ์ด ์ต์ ์ข ๋ฅ๊ฐ ๊ต์ฅํ ๋ง๋ค. ์ด๋ค์ ํ๋ํ๋ ๋ชจ๋ ์ตํ ํ์๋ ์๊ณ , ์ด์ค์์ ์ ์ฉํ ์ต์ ์ ์์ฃผ๋ก ๋ชจ์ ์ ๋ฆฌํด ๋ณด์๋ค.
Language and Environment ์ต์
target
์ด๋ ํ ๋ฒ์ ์ JavaScript ์ฝ๋๋ก ์ปดํ์ผ ํ ์ง ์ง์ ํ๋ค. ๋ง์ฝ ์ฝ๋๊ฐ ๊ตฌ์์ ํ๊ฒฝ์์ ๋ฐฐํฌ๋๋ค๋ฉด ๋ ๋ฎ์ ๋ฒ์ ์ ์ง์ ํด์ผ ํ๊ณ , ์ ์์ ํ๊ฒฝ์์๋ง ๋ฐฐํฌ๋๋ค๋ ๋ณด์ฅ์ด ์๋ค๋ฉด ๋ ๋์ ํ๊ฒ์ผ๋ก ์ง์ ํด๋ ๋๋ค. (์๋ฐ์คํฌ๋ฆฝํธ ๋ฒ์ ์ง์ ๊ฐ์ ๋ฃ์ง ์์ผ๋ฉด default๋ก es5๋ก ์ปดํ์ผ ๋๋ค)
๋ค๋ง ํ์ ์คํฌ๋ฆฝํธ ์์ค ์ฝ๋์ Promise ์ฝ๋๊ฐ ์์ ๊ฒฝ์ฐ, ์ด๋ ES5์์ ์ง์ํด์ฃผ์ง ์๊ธฐ ๋๋ฌธ์ Typescript๋ฅผ ์ปดํ์ผ ํ๋ฉด ์ค๋ฅ๊ฐ ๋ฐ์ํ๋ ์ด๋ถ๋ถ์ ์ ์ํด์ผ ํ๋ค.
๋๋ถ๋ถ์ ๋ธ๋ผ์ฐ์ ๋ ๋ชจ๋ ES6๋ฅผ ์ง์ํ๊ธฐ ๋๋ฌธ์, ๋ณดํต ES6๋ก ๋๊ณ ์ฌ์ฉ๋๋ ํธ์ด๋ค.
target ํ๋กํผํฐ๋ lib ํ๋กํผํฐ์ ๊ธฐ๋ณธ๊ฐ๋ ์๋์ผ๋ก ๊ฒฐ์ ์ํจ๋ค. ๋ฐ๋ผ์ target ํ๋กํผํฐ์ lib ํ๋กํผํฐ๋ฅผ ๊ถ์ฅ๋๋ ๋ฐฉ์๋๋ก ์ง์ ๋ง์ถ ์๋ ์์ง๋ง, ํธ์๋ฅผ ์ํด ๊ทธ๋ฅ target ํ๋กํผํฐ๋ง ์ง์ ํ ์๋ ์๋ค.
target ํ๋กํผํฐ ๊ฐ์ค์ ESNext ์ต์
๊ฐ์ด ์๋๋ฐ, ๊ฐ์ฅ ์ต์ ๊ธฐ๋ฅ์ ์๋ฐ์คํฌ๋ฆฝํธ ๋ฒ์ ์ ๊ฐ๋ฆฌํค๋ ๊ฐ์ด๋ค. ์ด ์ค์ ์ ์ฃผ์ ๊น๊ฒ ์ฌ์ฉ๋์ด์ผ ํ๋๋ฐ, ์๋ํ๋ฉด ํ์ฌ TypeScript์ ๋ฒ์ ์ ๋ฐ๋ผ ESNext๊ฐ ๊ฐ๋ฆฌํค๋ ๋ฒ์ ์ด ๋ฌ๋ผ์ง ์ ์๊ธฐ ๋๋ฌธ์ด๋ค.
"compilerOptions": {
"target": "ES6" // ์ด๋ค ๋ฒ์ ์ ์๋ฐ์คํฌ๋ฆฝํธ๋ก ์ปดํ์ผ ๋ ๊ฒ์ธ์ง ์ค์
// 'es3', 'es5', 'es2015', 'es2016', 'es2017','es2018', 'esnext' ๊ฐ๋ฅ
}
lib
lib ์ต์ ์ ์ปดํ์ผ์ ํ์ํ JavaScript ๋ด์ฅ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ง์ ํ ์ ์๋ค. Math API, document API ๋ฑ์ด ๊ทธ ์์์ด๋ค.
์ด ํ๋กํผํฐ๊ฐ ์ง์ ๋์ด ์์ง ์๋ค๋ฉด target ํ๋กํผํฐ์ ์ง์ ๋ ๋ฒ์ ์ ๋ฐ๋ผ ํ์ํ ํ์ ์ ์๋ค์ ๋ํ ์ ๋ณด๊ฐ ์๋์ผ๋ก ์ง์ ๋๋ค. ์๋ฅผ ๋ค์ด, target ํ๋กํผํฐ๊ฐ ES6 ํน์ ๊ทธ ์ด์์ ๋ฒ์ ์ผ๋ก ์ง์ ๋์๋๋ฐ, lib ํ๋กํผํฐ๊ฐ ์ง์ ๋์ง ์๋ค๋ฉด ์๋์ผ๋ก lib ํ๋กํผํฐ์๋ ES2015(lib.es2015.d.ts ํ์ผ) ๋ฑ์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ค์ด ์ง์ ๋๊ธฐ ๋๋ฌธ์ ๊ธฐ๋ณธ์ ์ผ๋ก ํ์ ์ ๋ณด๋ฅผ ์ ์ญ์ผ๋ก ์ฐธ์กฐํ ์ ์๊ฒ ๋๋ ๊ฒ์ด๋ค.
lib ํ๋กํผํฐ๋ฅผ ์ง์ ํ์ง ์์ ๋ ์๋์ผ๋ก ์ค์ ๋๋ ๊ฐ์ ๋ค์๊ณผ ๊ฐ๋ค.
- target์ด es3์ด๋ฉด ๋ํดํธ๋ก lib.d.ts๋ฅผ ์ฌ์ฉ
- target์ด es5์ด๋ฉด, ๋ํดํธ๋ก dom, es5, scripthost๋ฅผ ์ฌ์ฉ
- target์ด es6์ด๋ฉด, ๋ํดํธ๋ก dom, es6, dom.iterable, scripthost๋ฅผ ์ฌ์ฉ
"compilerOptions": {
"lib": ["es5", "es2015.promise", "dom"], // ์ปดํ์ผ ๊ณผ์ ์ ์ฌ์ฉ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ํ์ผ ์ค์
/*
es5: global type์ ์ฌ์ฉํ๊ธฐ ์ํจ (Array, Boolean, Function ๋ฑ..)
es2015.promise: Promise๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํจ
dom: setTimeout, console.log ๋ฑ dom์์ ์ง์ํด์ฃผ๋ ๊ธฐ๋ฅ๋ค์ ์ฌ์ฉํ๊ธฐ ์ํจ
*/
}
experimentalDecorators / emitDecoratorMetadata
ํ์ ์คํฌ๋ฆฝํธ์ @Decorator๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํด์๋ true๋ก ๋ฌ์ผ ์๋๋๋ค.
"compilerOptions": {
"experimentalDecorators": true /* ES7 ๋ฐ์ฝ๋ ์ดํฐ(decorators) ์คํ ๊ธฐ๋ฅ ์ง์ ์ค์ */
"emitDecoratorMetadata": true /* ๋ฐ์ฝ๋ ์ดํฐ๋ฅผ ์ํ ์ ํ ๋ฉํ๋ฐ์ดํฐ ๋ฐฉ์ถ ์คํ ๊ธฐ๋ฅ ์ง์ ์ค์ */
}
function methodDecorator() {
console.log('method');
return function (target: any, property: any, descriptor: any) {};
}
function propertyDecorator(writable: boolean = true) {
console.log('property');
return function (target: any, decoratedPropertyName: any): any {};
}
class Test {
@propertyDecorator()
property = 'property';
@methodDecorator()
test(param1: string) {
console.log('test1');
}
}
jsx
.tsx ํ์ฅ์์ ์ปดํ์ผ ๊ฒฐ๊ณผ JSX ์ฝ๋๋ฅผ ์ด๋ป๊ฒ ์ปดํ์ผํ ์ง ๊ฒฐ์ ํ๋ค.
- react : .js ํ์ผ๋ก ์ปดํ์ผ ๋๋ค. (JSX ์ฝ๋๋ React.createElement() ํจ์์ ํธ์ถ๋ก ๋ณํ๋จ)
- react-jsx : .js ํ์ผ๋ก ์ปดํ์ผ ๋๋ค. (JSX ์ฝ๋๋ _jsx() ํจ์์ ํธ์ถ๋ก ๋ณํ๋จ)
- react-jsxdev : .js ํ์ผ๋ก ์ปดํ์ผ ๋๋ค. (JSX ์ฝ๋๋ _jsx() ํจ์์ ํธ์ถ๋ก ๋ณํ๋จ)
- preserve : .jsx ํ์ผ๋ก ์ปดํ์ผ ๋๋ค. (JSX ์ฝ๋๊ฐ ๊ทธ๋๋ก ์ ์ง๋จ)
- react-native : .js ํ์ผ๋ก ์ปดํ์ผ ๋๋ค. (JSX ์ฝ๋๊ฐ ๊ทธ๋๋ก ์ ์ง๋จ)
"compilerOptions": {
"jsx": "preserve" // tsx ํ์ผ์ jsx๋ก ์ด๋ป๊ฒ ์ปดํ์ผํ ๊ฒ์ธ์ง 'preserve', 'react-native', 'react'
}
Modules ์ต์
rootDir
๋ฃจํธ ๋๋ ํ ๋ฆฌ ๊ธฐ์ค์ ๋ณ๊ฒฝํ๋ค. js ์์ํ ๊ฒฝ๋ก์ ์ํฅ์ ์ค ์ ์๋ค.
module / moduleResolution
ํ๋ก๊ทธ๋จ์์ ์ฌ์ฉํ ๋ชจ๋ ์์คํ ์ ๊ฒฐ์ ํ๋ค.
๋ง์ผ import ๊ตฌ๋ฌธ์ es6๋ก ์ปดํ์ผ ํ์๋, ๋์ผํ๊ฒ import๋ก ์ปดํ์ผ๋์ด commonJSํ๊ฒฝ์ node๋ก ์คํ์ ์ค๋ฅ๊ฐ ๋ฐ์ ํ ์๋ ์๋ค.
๋ฐ๋ผ์ import ๊ตฌ๋ฌธ์ require ๊ตฌ๋ฌธ์ผ๋ก ์ปดํ์ผ์ ํด์ค์ผํ ๋ module์ ์์ฑ๊ฐ์ commonJS๋ก ์ง์ ํ๋ฉด ๋๋ค.
- CommonJS (target ํ๋กํผํฐ๊ฐ ES3 ํน์ ES5๋ก ์ง์ ๋์์ ๋์ ๊ธฐ๋ณธ๊ฐ)
- ES6/ES2015 (target ํ๋กํผํฐ๊ฐ ES6 ํน์ ๊ทธ ์ด์์ ๋ฒ์ ์ผ๋ก ์ง์ ๋์์ ๋์ ๊ธฐ๋ณธ๊ฐ)
- ๋๋จธ์ง (ES2020, ESNext, AMD, UMD, System, None)
์ฐธ๊ณ ๋ก module ํ๋กํผํฐ๋ moduleResolution ํ๋กํผํฐ์ ๊ธฐ๋ณธ๊ฐ๋ ๊ฒฐ์ ํ๋ค.
module์ด commonjs๋ฉด ๋ ธ๋์์ ์๋ํ๋ ๊ฒ์ ์๋ฏธํ๋ฏ๋ก, moduleResoultion ํค ๊ฐ์ node์ด๋ฉฐ, ๋ง์ผ module์ด amd(์น)๋ฉด classic์ผ๋ก ์ค์ ๋๋ค.
"compilerOptions": {
"module": "commonjs", /* ์์ฑ๋ ๋ชจ๋ ์ฝ๋ ์ค์ : 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
"moduleResolution": "node", /* ๋ชจ๋ ๋ถ์ ๋ฐฉ๋ฒ ์ค์ : 'node' (Node.js) ๋๋ 'classic' (TypeScript pre-1.6). */
}
baseURL / paths
import ๊ตฌ๋ฌธ์ ๋ชจ๋ ํด์ ์์ ๊ธฐ์ค์ด ๋๋ ๊ฒฝ๋ก๋ฅผ ์ง์ ํ๋ค.
๊ฐ๋ฐ์ ํ๋ค ๋ณด๋ฉด, ๋ ธ๋ ํจํค์ง ์ด์ธ์๋, ์ง์ ๋ง๋ ์์ค ํ์ผ์ import ์์ผ์ผ ํ๋ ๋๊ฐ ๋ฐ์ํ๋ค. ๊ทธ๋์ ํ์ผ์ ์๋จ์๋ ๋ค์๊ณผ ๊ฐ์ด ์ ์ญ๊ฒฝ๋ก ์ ์๋๊ฒฝ๋ก ๊ธฐ์ค์ผ๋ก ๊ฐ๊ฐ import ํ๊ฒ ๋๋ค.
import styled from 'styled-components'; // ๋
ธ๋ ํจํค์ง์ผ ๊ฒฝ์ฐ ์ต์๋จ ๊ฒฝ๋ก์ ์๋ node_modules ํด๋๋ฅผ ์๋ ์ธ์
import { TextField } from '../../../../components/textfield'; // ์ง์ ๋ง๋ ์ฌ์ฉ์ฌ ์์ค ํ์ผ์ด ์์ ๊ฒฝ์ฐ ์๋๊ฒฝ๋ก๋ก ๊ฐ์ ธ์์ผ ํ๋ค.
...
โ../../../../index.tsโ๊ฐ์ด import ํ๋ ์ด๋ฐ ๋ฐฉ์์ด ์ข ์์์ง ์์๋ ์ผ๋จ ์๋ํ๋๋ฐ๋ ๋ฌธ์ ๊ฐ ์์ง๋ง, ์ถํ ๊ณ์ ํ๋ก์ ํธ๋ฅผ ์์ฑํ๊ฑฐ๋ ๋ฆฌํฉํ ๋ง ํ ๋ ๋ฌธ์ ๊ฐ ๋ฐ์ํ ์ ์๋ค.
์๋ฅผ๋ค์ด ์๋ ๊ฒฝ๋ก๋ ํ์ฌ ์์นํ๊ณ ์๋ ํ์ผ ๊ฒฝ๋ก์ ๋ฐ๋ผ ์ผ๋ง๋ ์ง ๋ฌ๋ผ์ง์๊ฐ ์๊ธฐ ๋๋ฌธ์, ๋ง์ผ ๋ค๋ฅธ ๊ฒฝ๋ก์ ํ์ผ์ ๋ง๋ค์ด์ ๋์ผํ ๋ชจ๋์ import ํ๋ ค๊ณ ํ๋ฉด, ์์น ๊ธฐ์ค์ ์ด ๋ฌ๋ผ์ง๊ธฐ ๋๋ฌธ์ ๋ค๋ฅด๊ฒ ์๋๊ฒฝ๋ก๋ฅผ ์ฐพ์ ๋ค์ด๊ฐ์ผ ๋์ ๊ต์ฅํ ๋ฒ๊ฑฐ๋ก์ ์ง๋ค.
๋ฐ๋ก ์ด๋ baseUrl ์์ฑ ๊ณผ paths ์์ฑ์ ์ค์ ํ๋ฉด ์ ๋๊ฒฝ๋ก๋ก import ํ ์ ์๊ฒ ๋๋ค. ๊ทธ๋ผ ์๋์ ๊ฐ์ด ์ ๋๊ฒฝ๋ก๋ก ๊น๋ํ๊ฒ ์์ฑํ ์ ์๋ค.
import styled from 'styled-components';
import { TextField } from '@components/textfield';
...
์ฒซ ๋ฒ์งธ๋ก baseUrl ์์ฑ์ ๊ธฐ๋ณธ ๊ฒฝ๋ก๋ฅผ ์ค์ ํด ์ฃผ๊ณ ๊ทธ ๋ฐ๋ก ์๋์ paths ์์ฑ์ ์ ๋ ๊ฒฝ๋ก๋ฅผ ์ง์ ํ๊ณ ์ถ์ ๊ฒฝ๋ก๋ค์ ์ง์ ํด ์ฃผ๋ฉด ๋๋ค. ์ถ๊ฐ์ ์ผ๋ก outDir ๋ ์ค์ ํด์ค๋ค.
{
"compilerOptions": {
"baseUrl": "./", // ์ ๋ ๊ฒฝ๋ก ๋ชจ๋์ด ์๋, ๋ชจ๋์ด ๊ธฐ๋ณธ์ ์ผ๋ก ์์นํ ๋๋ ํ ๋ฆฌ ์ค์
"paths": { // 'baseUrl'์ ๊ธฐ์ค์ผ๋ก ์๋ ์์น๋ก ๊ฐ์ ธ์ค๊ธฐ๋ฅผ ๋ค์ ๋งคํํ๋ ํญ๋ชฉ ์ค์
"@components/*": [
"src/components/*" // import {} from '@components/ํ์ผ' ํ ๋ ์ด๋ ๊ฒฝ๋ก๋ก ์ฐพ์๋ค์ด๊ฐ์ง paths ์ค์
],
"@utils/*": [
"src/utils/*"
],
},
"outDir": "./dist", // ์ปดํ์ผํ ๋ js ํ์ผ ์์น ๊ฒฝ๋ก ์ง์
},
}
๊ทธ๋ฌ๋ ์ค์ ts-node๋ฅผ ์ด์ฉํด ์์ค ํ์ผ์ ์คํํด๋ณด๋ฉด ์ค๋ฅ๊ฐ ๋๋ค. ์๋ํ๋ฉด tsconfig.json ์ค์ ์ ๊ฒฝ๋ก alias๋ง ์ค๊ฒ์ด์ง ์ค์ ๊ฒฝ๋ก๋ฅผ ๋ฐ๊พผ๊ฒ ์๋๊ธฐ ๋๋ฌธ์ด๋ค.
๋ฐ๋ผ์ ๋ณ๋๋ก tsconfig-paths ์ tsc-alias ๋ผ๋ ๋ชจ๋์ด ์ค์นํด์ฃผ์ด์ผ ํ๋ค.
[ tsconfig-paths ]
tsconfig.json ๋ด์ baseurl ์ด๋ pathsํ๋์ ๋ช ์๋ ๋ชจ๋์ ์ค์ ๋ก ํธ์ถํ๊ฒ ๋์์ฃผ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
[ tsc-alias ]
js ํ์ผ๋ก ์ปดํ์ผ๋๋ฉด baseurl ์ด๋ paths ํ๋๋ก ๋ช ์๋ ๊ฒฝ๋ก๊ฐ ๊ทธ๋๋ก ํธ๋์คํ์ผ๋ง ๋์ js ๋ชจ๋์ ์ธ์ํ ์ ์๋ ํ์์ด ์ผ์ด๋๊ฒ ๋๋๋ฐ, ์ด ํจํค์ง๋ฅผ ์ด์ฉํ๋ฉด ์ปดํ์ผ๋ ๊ฒฝ๋ก๋ฅผ ์๋๊ฒฝ๋ก๋ก ๋ฐ๊ฟ์ ํด๊ฒฐ์ด ๊ฐ๋ฅํ๋ค.
> npm i -D tsconfig-paths tsc-alias
๊ทธ๋ฆฌ๊ณ tsconfig.json ํ์ผ์์ ์ ์ญ ์์ฑ์ผ๋ก ๋ค์๊ณผ ๊ฐ์ด ์ถ๊ฐ ์ค์ ์ ํด์ค๋ค.
{
"compilerOptions": {
"baseUrl": "./"
"path": ...
},
// ์ ์ญ ์์ฑ์ผ๋ก ์ถ๊ฐํด์ค๋ค.
"ts-node": {
"require": ["tsconfig-paths/register"]
}
}
์กฐ์ฌํด์ผ ํ ์ ์, @๋ก ์์ํ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ npm์ ํตํด ๋ฐ์์ ์ฌ์ฉํ ๋ alias ๋ช ์นญ๊ณผ ์ค๋ณต๋์ง ์๊ฒ ๋ฑ๋กํด์ผ ํ๋ค.
๊ทธ๋ฆฌ๊ณ ts-node index.ts ๋ช ๋ น์ด๋ฅผ ์คํํด๋ณด๋ฉด, @๊ฒฝ๋ก๋ฅผ ์ ์ฐพ์๋ค์ด๊ฐ๋ ๊ฑธ ํ์ธ ํ ์ ์๋ค. ๋ฐฐํฌํ๊ฒฝ์ ๋น๋ ๊ฐ์ ๊ฒฝ์ฐ, ์ปดํ์ผ ๋ช ๋ น์ด๋ฅผ ๋ค์๊ณผ ๊ฐ์ด ํ๋ฉด ๋๋ค.
> tsc && tsc-alias
package.json์ script๋ ์ค์ ํด์ฃผ๋ฉด ์ข์.
"scripts": {
"build": "tsc --project tsconfig.json && npx tsc-alias -p tsconfig.json",
}
types / typeRoots
tsconfig๋ ๊ธฐ๋ณธ์ ์ผ๋ก node_modules ํด๋๋ฅผ ์ ์ธํ์ง๋ง, ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ํ์ ์ ์ ์ํด๋๋ @types ํด๋๋ ์ปดํ์ผ์ ์๋์ผ๋ก ๊ฒฝ๋ก์ ํฌํจ๋๋ค. ๊ทธ๋ฐ๋ฐ ๋ง์ฝ ์ด @types์ ๊ธฐ๋ณธ ๊ฒฝ๋ก๋ฅผ ๋ณ๊ฒฝํ๊ณ ์ถ๋ค๋ฉด ์๋์ ๊ฐ์ด ์ง์ ํ ์ ์๋ค.
"compilerOptions": {
"typeRoots": ["./my-tslib"], // ์ปดํ์ผ ๋ชฉ๋ก์ ์๋์ผ๋ก ํฌํจ์ํฌ ํจํค์ง๋ค์ ๊ธฐ์ค ๋๋ ํ ๋ฆฌ
// .d.ts ํ์ผ์ ์ฝ์ ํด๋๋ฅผ node_modules/@types์์ node_modules/my-tslib๋ก ๋ณ๊ฒฝ
"types": ["node", "jest", "express"], // typeRoots ๋๋ ํ ๋ฆฌ ๋ด์ ์กด์ฌํ๋ ํจํค์ง๋ค ์ค ์ด๋ค ํจํค์ง๋ค์ ์ปดํ์ผ ๋ชฉ๋ก์ ํฌํจ์ํฌ์ง
// ๋ง์ฝ types๊ฐ ์ง์ ๋์ด ์์ง ์๋ค๋ฉด typeRoots์ ์ง์ ๋ ๊ฒฝ๋ก์ ํจํค์ง๋ค์ ์ ๋ถ ์ปดํ์ผ ๋ชฉ๋ก์ ์๋์ผ๋ก ํฌํจ
}
resolveJsonModule
ํ์ฅ์๊ฐ .json์ธ ๋ชจ๋์ import๋ฅผ ํ์ฉํ๋ ์ค์ ์ด๋ค. ์๊ฐํด ๋ณด๋ฉด Node.js ์๋ฐ์คํฌ๋ฆฝํธ ํ๋ก์ ํธ์์ json ์ค์ ํ์ผ์ importํด์ ์์ฃผ ์ฌ์ฉํด์จ๊ฑธ ๋ ์ฌ๋ฆด ๊ฒ์ด๋ค. ํ์ ์คํฌ๋ฆฝํธ๋ ๊ฐ๋ฅํ ๊ฒ์ด๋ผ ์๊ฐํ์ง๋ง, json์ ํ๋กํผํฐ๋ค์ ์น๋ค ํ์ ์ ์ง์ ํด์ผ ์ฌ์ฉ์ด ๊ฐ๋ฅํ๋ค.
์ด ์ต์ ์ json์ ํ์ ์ ์๋์ผ๋ก ์ค์ ํด์ค์ ๋ฐ๋ก ๋ณํ ์์ ์์ด ํ์ ์คํฌ๋ฆฝํธ์์ json ํ์ผ ๋ฐ์ดํฐ๋ค์ ๊ณง๋ฐ๋ก ์ฌ์ฉํ ์ ์๋๋ก ํด์ค๋ค.
์๋ฅผ ๋ค์ด ๋ค์๊ณผ ๊ฐ์ json ๋ฐ์ดํฐ๊ฐ ์๋ค๊ณ ํ์.
{
"name":"ํ๊ธธ๋",
"age": 54,
"height": 170,
"married": false
}
์๋๋ผ๋ฉด ์ด๋ ๊ฒ ts ํ์ผ์์ ์ฌ์ฉํ ์ ์๊ฒ ๋งํ์๋ค.

resolveJsonModule ์ต์
์ true๋ก ์ค์ ํด์ฃผ๋ฉด, ๋ค์๊ณผ ๊ฐ์ด ์๋์ผ๋ก ํ์
์ด ๋งคํ๋์ด ์ฌ์ฉ์ด ๊ฐ๋ฅํด์ง๋ค.
"compilerOptions": {
"resolveJsonModule": true, // ts ํ์ผ์์ json imoprt ํ์ฉ
}

Interop Constraints ์ต์
esModuleInterop
๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ค์์๋ amd(์น) ๋ฐฉ์์ ์ ์ ๋ก ๊ตฌํ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ์๋๋ฐ commonjs ๋ฐฉ์์ผ๋ก ๋์ํ๋ TS์์๋ ํผ๋์ ์ค ์ ์๋ค. ์ํธ ์ด์ฉ์ (interoperable)์ผ๋ก ์ฌ์ฉํ๊ธฐ ์ํด์๋ ๊ฐ๋ฅํ true๋ก ์ง์ ํด ๋๊ณ ํ์ ์คํฌ๋ฆฝํธ ์ฝ๋ฉ์ ํ๋๊ฒ์ ๊ถํ๋ค.
"compilerOptions": {
"esModuleInterop": true, /* ๋ชจ๋ ๊ฐ์ ธ์ค๊ธฐ์ ๋ํ ๋ค์์คํ์ด์ค ๊ฐ์ฒด ์์ฑ์ ํตํด CommonJS์ ES ๋ชจ๋ ๊ฐ์ ์ํธ ์ด์ฉ์ฑ์ ์ ๊ณต */
}
// esModuleInterop: true์ผ ๊ฒฝ์ฐ ๊ฐ๋ฅํจ
import React from "react";
// false์ธ ๊ฒฝ์ฐ ๋ค์๊ณผ ๊ฐ์ด import ํด์ผ ํจ
import * from React from "react";
forceConsistentCasingInFileNames
ํ์ผ์ ์ด๋ฆ์ ๋์๋ฌธ์ ํ๋ณํ๊ฒ ํ๋ ์ต์ ์ด๋ค.
ํ๋ก๊ทธ๋๋ฐ ์ธ๊ณ์์ ๊ฐ์ ์ํ๋ฒณ์ด๋ผ๋ ๋์๋ฌธ์๋ฅผ ๋ชจ๋ ๊ตฌ๋ถํ๊ธฐ ๋๋ฌธ์ ์ด ์ต์ ์ ๊ฐ๋ฅํ true๋ก ํด๋๊ณ ์ฌ์ฉํ๊ธฐ๋ฅผ ๊ถ์ฅํ๋ค.
JavaScript Support ์ต์
allowJs
TypeScript ํ๋ก์ ํธ์์ JavaScript ํ์ผ๋ ์ฌ์ฉํ ์ ์๋๋ก ํ๋ ์ค์ ์ด๋ค. allowJs: true์ด๋ฉด JavaScript ํ์ผ๋ค๋ ํ์
์คํฌ๋ฆฝํธ ํ๋ก์ ํธ์์ import ๋ ์ ์๋ค.
๊ธฐ๋ณธ์ ์ผ๋ก ํ์ ์คํฌ๋ฆฝํธ๋ .js ํ์ฅ์๋ฅผ ํ์ฉํ์ง ์๋๋ค. ๊ทธ๋์ ๋ง์ผ ์๋ฐ์คํฌ๋ฆฝํธ๋ฅผ ํ์ ์คํฌ๋ฆฝํธ๋ก ๋ฐ๊พธ๋ ํ๋ก์ ํธ๊ฐ ์งํ์ค์ด๋ผ๋ฉด ๊ณค๋ํจ์ ๊ฒช๊ฒ ๋๋ค. ๋ฐ๋ผ์ ์ด ์์ฑ์ JavaScript ํ๋ก์ ํธ๋ฅผ TypeScript ํ๋ก์ ํธ๋ก ๋ฐ๊พธ๋ ค ํ ๋ ์ ์ง์ ์ผ๋ก ๋ณํํ๊ธฐ ์ํ ์ฉ๋๋ก ์ฌ์ฉ๋๋ค.
"compilerOptions": {
"allowJs": true,
}
checkJs
ts ํ์ผ ๋ฟ๋ง ์๋๋ผ, js ํ์ผ์ ์๋ ์๋ฌ๋ ๋ณด๊ณ ํ๋ผ๋ ์ต์ ์ด๋ค. ๋ณดํต allowJS ์์ฑ๊ณผ ํจ๊ป ์ฌ์ฉ๋๋ค.
"compilerOptions": {
"allowJs": true, // js ํ์ผ๋ค ts์์ importํด์ ์ธ ์ ์๋์ง
"checkJs": true, // ์ผ๋ฐ js ํ์ผ์์๋ ์๋ฌ์ฒดํฌ ์ฌ๋ถ
}
Emit ์ต์
outFile
์ผ๋ฐ์ ์ธ ํํ๋ก๋ ํ๋์ ํ์ผ๋ก ๋ง๋ค์ ์์ง๋ง, ๋ฒ๋ค๋ฌ ํํ๋ก ์ง์ํ์ฌ ํ๋๋ก ๋ง๋ ๋ค.
๋จ, ๋ชจ๋์ด ์์คํ ํน์ amd์ ๊ฐ์ ํํ๋ก ์ง์๋์ด์ผ ํ์ผ์ ํ๋๋ก ๋ง๋ค์ ์์ด์, ์ฐจ๋ผ๋ฆฌ ๋ฐ๋ก ์นํฉ์ ์ฌ์ฉํ์ง ์ด ๊ธฐ๋ฅ์ ์ด์ฉํ์ง๋ ์์ ์ค์๋๊ฐ ๋ฎ์ ์ต์ ์ด๋ค.
outDir
๊ธฐ๋ณธ์ ์ผ๋ก ์ปดํ์ผ์ ์งํํ๋ฉด .ts์ ๊ฐ์ ๊ฒฝ๋ก์ .js ๊ฒฐ๊ณผ๋ฌผ์ ์์ฑํ๋๋ฐ, outDir ์ต์ ์ผ๋ก ๊ฒฝ๋ก๋ฅผ ์์ ํ์ฌ ์ปดํ์ผ๋ js ํ์ผ๋ค์ ๋ด์ ํด๋๋ฅผ ์ง์ ํด์ค ์ ์๋ค.
"compilerOptions": {
"outDir": "./dist"
}
noEmit
ํ์ ์คํฌ๋ฆฝํธ๋ฅผ ์ปดํ์ผํ๋ฉด, JavaScript ๋ณํ ํ์ผ์ ๋ง๋ค์ด ๋ด์ง ์๋๋ก ํ๋ ์ค์ ์ด๋ค.
์ด๋ ๊ณง ํ์ ์คํฌ๋ฆฝํธ๋ฅผ ์๋ํฐ ํตํฉ ๊ธฐ๋ฅ์ ์ ๊ณตํ๊ธฐ ์ํ ๋๊ตฌ ํน์ ์์ค ์ฝ๋ ํ์ ์ฒด์ปค๋ก๋ง ์ฌ์ฉํ๊ฒ ๋๋ ๊ผด์ด ๋๋ค.
๋ง์ผ Babel์ด๋ swc์ ๊ฐ์ ๋ ๋ค๋ฅธ ๋๊ตฌ๊ฐ ๋ณํํ๋ ์์ ์ ๋์ ๋ด๋นํ๋ ๊ฒฝ์ฐ ์ฌ์ฉ๋๋ ์ต์ ์ด๋ผ๊ณ ์ดํดํ๋ฉด ๋๋ค.
"compilerOptions": {
"noEmit": true,
}
sourceMap
์ปดํ์ผ๋ ํ์ผ ๋๋ ํฐ๋ฆฌ์ .js.map ํ์ผ์ด ๋ง๋ค์ด์ง๋ค.
์ด ์์ค๋งต ํ์ผ์ ๋ณํ๋ js์ฝ๋๊ฐ ts์ ์ด๋์ ํด๋นํ๋ ์ง๋ฅผ ์๋ ค์ค๋ค. ๋๋ฒ๊น ์์ ์ ๋งค์ฐ ์ ์ฉํ๋ค.
"compilerOptions": {
"sourceMap": true, /* ์์ค๋งต '.map' ํ์ผ ์์ฑ ์ค์ */
}
์ค์ ๋ก ํ์ ์คํฌ๋ฆฝํธ ํ๋ก์ ํธ๋ฅผ ๋ฐฐํฌํ๊ณ , ๋ธ๋ผ์ฐ์ ์์ ๊ฐ๋ฐ์๋ชจ๋๋ฅผ ์ด์ฉํด source ํญ์ ๋ณด๋ฉด, ๋ธ๋ผ์ฐ์ ๋ js๋ง ์ธ์ํ์ง๋ง ๋งคํ ํ์ผ์ ์ํด ts ํ์ผ์ ์ธ์ํ๋๊ฑธ ๋ณผ ์ ์๋ค.
์ด๋ ๊ฒ ์ง์ ํ์ ์คํฌ๋ฆฝํธ ํ์ผ์ ์๋ชป๋ ๋ถ๋ถ์ด ์์ผ๋ฉด ์ง์ ๋๋ฒ๊น ํ ์ ์๋ค.

downlevelIteration
ํ์
์คํฌ๋ฆฝํธ์์ ์ ๋๋ ์ดํฐ function* {}, yeild... ๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํ ์ต์
์ฝ๋๋ฅผ ์ด์ ๋ฒ์ ์ js๋ก ์ปดํ์ผํ๊ณ for loop๋ก ์์ ํ๋ฉด ์ปดํ์ผ์ด ์ ๋๋ก ์๋ํ์ง ์์ ์ ์์ด, ์ด ์์ฑ์ ์ค์ ์ ํด๋์ผ๋ฉด ์ ํ๋๊ฐ ์ฌ๋ผ๊ฐ์ง๋ง js์ฝ๋๋์ด ๋์ด๋๊ธฐ ๋๋ฌธ์, ์๋ํ๋๋ก loop๊ฐ ์๋ํ์ง ์์ ๋๋ง ์ฌ์ฉํ๊ธธ ๊ถํ๋ค.
"compilerOptions": {
"downlevelIteration": true, //* 'ES5' ํน์ 'ES3' ํ๊ฒ ์ค์ ์ Iterables 'for-of', 'spread', 'destructuring' ์๋ฒฝ ์ง์ ์ค์ */
}
removeComments
์ปดํ์ผ ์ ํ์ ์คํฌ๋ฆฝํธ ์์ค์ ์ฃผ์์ ๋ชจ๋ ์ ๊ฑฐํ๋ ๊ฒ์ ์ค์ ํ๋ค.
"compilerOptions": {
removeComments": true, // true๋ฉด ์ปดํ์ผ๋ js์ ๊ธฐ์กด์ ์ฃผ์์ ๋ชจ๋ ์ ๊ฑฐ
}
noEmitOnError
์๋๋ ํ์ ์คํฌ๋ฆฝํธ์ ๊ตฌ๋ฌธ ์๋ฌ๊ฐ ๋ฐ์ํ๋๋ผ๋, ์ปดํ์ผํ๋ฉด jsํ์ผ์ ์์ฑํ๋๋ฐ, ์ ์ค์ ์ true๋ก ์ค์ ํ๋ฉด ์๋ฌ๊ฐ ๋ฐ์ํ tsํ์ผ์ ์ปดํ์ผ์ ๋ง๋๋ค.
"compilerOptions": {
noEmitOnError": true, // ์ปดํ์ผ ์๋ฌ๊ฐ ์์ผ๋ฉด js ์ปดํ์ผ ํ์ง ์์
}
declaration
์ด ์ต์ ์ true๋ก ํ๋ฉด TSํ์ผ์ JS๋ก ์ปดํ์ผํ๋ ๊ณผ์ ์์ JSํ์ผ๊ณผ ํจ๊ป d.ts ํ์ผ์ด ์์ฑ๋๊ฒ ํ๋ค.
๊ฐ์ฒด๋ ํจ์๋ฅผ ์ฐ๋ค๋ณด๋ฉด ํ์ ์ ์ปค์คํ ํ๋ ๊ฒฝ์ฐ๊ฐ ์จ๋ค. ์ด๋ ํ์ ๋ค์ tsํ์ผ์ ๋ฃ์ด๋ ๋์ง๋ง ์ฉ๋๊ฐ ๋ค๋ฅด๊ธฐ๋๋ฌธ์ ๋ถ๋ฆฌํ๋ ๊ฒ์ด ์ข๋ค. ๊ทธ๋ด๋ d.tsํ์ผ์ ๋ง๋ค์ด ๋ฐ๋ก ํ์ ๋ง์ ๊ด๋ฆฌํ๋๋ฐ ์ด๋ด๋ ์ฌ์ฉ๋๋ ์ต์ ์ด๋ค.
"compilerOptions": {
"declaration": true, //์ปดํ์ผ์ .d.ts ํ์ผ๋ ์๋์ผ๋ก ํจ๊ป์์ฑ (ํ์ฌ์ฐ๋ ๋ชจ๋ ํ์
์ด ์ ์๋ ํ์ผ)
}

Type Checking ์ต์
strict
ํ์ ์คํฌ๋ฆฝํธ์ ๊ฐ์ข ํ์ ์ฒดํน ๋์์ ์ ๋ถ ํ์ฑํํ๋ค.
์ฌ์ค์ ์ด ์ต์ ์ ์ฐ์ง์๋๊ฒ์ ๊ณง ํ์ ์คํฌ๋ฆฝํธ๋ฅผ ์ฐ์ง ์๋ ๋ค๋ ๊ฒ๊ณผ ๊ฐ๋ค. ๋ฐ๋ผ์ ๊ธฐ๋ณธ์ผ๋ก ํ์ฑํ ๋์ด ์๋ค.
"compilerOptions": {
"strict": true /* ๋ชจ๋ ์๊ฒฉํ ์ ํ ๊ฒ์ฌ ์ต์
ํ์ฑํ */
}
์ด ํ๋กํผํฐ๋ฅผ true๋ก ์ง์ ํ๋ฉด strict mode family ํ๋กํผํฐ๋ค์ ์ ๋ถ true๋ก ์ง์ ํ๋ ๊ฒ๊ณผ ๋์ผํ๋ค.
๋ง์ผ ์ฌ์ํ ๋ถ๋ถ์๋ ๋๋ฌด ์ง๋์น๊ฒ ๋นจ๊ฐ์ค์ ๊ธ๋๊ฒ ๋ถํธํ๋ค๋ฉด, ์ ํ์ ์ผ๋ก ๋ช ๊ฐ์ strict mode family ํ๋กํผํฐ๋ฅผ false๋ก ์ง์ ํ๋ ์์ผ๋ก ์ค์ ํ๋ฉด ๋๋ค.
[strict mode family ํ๋กํผํฐ๋ค]
- alwaysStrict ํ๋กํผํฐ
- strictNullChecks ํ๋กํผํฐ
- strictBindCallApply ํ๋กํผํฐ
- strictFunctionTypes ํ๋กํผํฐ
- strictPropertyInitialization ํ๋กํผํฐ
- noImplicitAny ํ๋กํผํฐ
- noImplicitThis ํ๋กํผํฐ
noImplicitAny
๋ช ์์ ์ด์ง ์์ any ํ์ ์ด ์ง์ ๋ ๊ฒฝ์ฐ ํํ์๊ณผ ์ ์ธ์ ์ฌ์ฉํ๋ฉด ์๋ฌ ๋ฐ์ ์ํจ๋ค.
์๋ฅผ๋ค์ด ํ์ ์คํฌ๋ฆฝํธ๊ฐ ์ถ๋ก ์ ์คํจํด์ any๋ก ์ง์ ๋๋ฉด ๋นจ๊ฐ์ค์ด ๋จ๊ฒ ๋๋๋ฐ, ์ด๋ ์ง์ any๋ผ๊ณ ์ง์ ํด์ผ ๋นจ๊ฐ์ค์ด ์ฌ๋ผ์ง๋ค.
์์ strict ์ต์
์ true๋ก ํ๋ฉด noImplicitAny ์ต์
๋ ์๋์ผ๋ก true๊ฐ ๋์ ๋ํ๋๋ ํ์์ธ๋ฐ, ์ด๋ ์ด ์ต์
์ false๋ก ์ง์ ํ๋ฉด ์๋์ ๊ฐ์ด any ํ์
์ ๋ช
์์ ์ผ๋ก ์ง์ ์ํด๋ ์ค๋ฅ๊ฐ ์ฌ๋ผ์ง๊ฒ ๋๋ค.
"compilerOptions": {
"strict": true,
"noImplicitAny": false /* ๋ช
์์ ์ด์ง ์์ 'any' ์ ํ์ผ๋ก ํํ์ ๋ฐ ์ ์ธ ์ฌ์ฉ ์ ์ค๋ฅ ๋ฐ์ */
}
function methodDecorator() {
console.log('method');
return function (target, property, descriptor) {}; // noImplicitAny: false๋ก ํ๋ฉด, ๋ช
์์ any๋ฅผ ์์จ๋ ์๋ฌ๊ฐ ์๋๋ค.
}


suppressImplicitAnyIndexErrors
nolmplicitAny๋ฅผ ์ฌ์ฉํ ๋ ์ธ๋ฑ์ค ๊ฐ์ฒด์ ์ธ๋ฑ์ค ์๊ทธ๋์ฒ๊ฐ ์๋ ๊ฒฝ์ฐ ์ค๋ฅ๊ฐ ๋ฐ์ํ๋ ๊ฒ์ ์์ธ ์ฒ๋ฆฌ ํด์ค๋ค.
์๋ฅผ๋ค์ด suppressImplicitAnyindexErrors์ต์
์ true๋ก ์ค์ ํด์ฃผ๋ฉด, person ๊ฐ์ฒด์ age ๋ผ๋ ํ๋กํผํฐ๊ฐ ์์ด๋ person['age'] ๋ฅผ ์๋ฌ๋ฅผ ๋ด์ฃผ์ง ์๋๋ค.
"compilerOptions": {
"strict": true,
"suppressImplicitAnyIndexErrors": true,
}
const person = {
name: 'ํ๊ธธ๋',
};
console.log(person['age']); // suppressImplicitAnyIndexErrors: true๋ก ํ๋ฉด ๊ทธ๋ฅ undefined๋ฅผ ์ถ๋ ฅํ๋ค

noImplicitThis
์์์ any ์ ํ์ด ์๋ this ํํ์์์ ์ค๋ฅ๋ฅผ ๋ฐ์์ํจ๋ค.
๋ณธ๋๋ผ๋ฉด ๋ช ์์ this๋ฅผ ํตํด ์ค๋ฅ๋ฅผ ํด๊ฒฐํ์ง๋ง, this์ any๊ฐ ์ค๋๊ฑธ ํ์ฉํ๋ค๋ฉด ์ด ์ต์ ์ false๋ก ์ง์ ํด์ฃผ์ด ๋นจ๊ฐ์ค์ ์ง์ธ ์ ์๋ค.
"compilerOptions": {
"strict": true,
"noImplicitThis": false, /* ๋ช
์์ ์ด์ง ์์ 'any'์ ํ์ผ๋ก 'this' ํํ์ ์ฌ์ฉ ์ ์ค๋ฅ ๋ฐ์ */
}
class Rectangle {
width: number;
height: number;
constructor(width: number, height: number) {
this.width = width;
this.height = height;
}
getAreaFunction() {
return function () {
return this.width * this.height; // ์๋๋ ๋ช
์์ this๋ฅผ ์จ์ผํ์ง๋ง, "noImplicitThis": false ํ๋ฉด ์์จ์ค๋ ๋๋ค.
};
}
}

strictNullChecks
null๋ฐ undefined ๊ฐ์ ๋ํ ์ ํ์ ์กฐ์ ํ๋ ์ต์ ์ด๋ค.
strickNullChecks๋ฅผ ์ ์ฉํ๋ฉด, ๋ชจ๋ ํ์ ์ null, undefined๊ฐ์ ๊ฐ์ง ์ ์๊ณ ๊ฐ์ง๋ ค๋ฉด union type์ผ๋ก ์ง์ ๋ช ์ํด์ผ ํ๋ค.
๋จ, ๊ธฐ๋ณธ์ ์ผ๋ก any์ null, undefinedํ ๋น ๊ฐ๋ฅํ๋ฉฐ void์๋ undefined ํ ๋น ๊ฐ๋ฅํ๋ค.
ํจ์๋ฅผ ์ ์ธํ ๋๋ถํฐ ๋งค๊ฐ๋ณ์์ ๋ฆฌํด ๊ฐ์ ์ ํํ ํ์ ์ ์ง์ ํ ์ ์๋ ํจ๊ณผ๊ฐ ์๋ค.
๋ง์ผ strickNullChecks๋ฅผ ์ ์ฉํ์ง ์์ ๊ฒฝ์ฐ ๋ชจ๋ ํ์ ์ null, undefined๊ฐ์ ํ ๋น ๊ฐ๋ฅํด์ง๋ค.
"compilerOptions": {
"strict": true,
"strictNullChecks": false, /* ์๊ฒฉํ null ๊ฒ์ฌ ์ฌ์ฉ */
}

์ด ์ต์ ์ ์ ๋งํ๋ฉด ํ์ฑํ ํด์ฃผ๋๊ฒ ์ข์๋ฐ, ๋ค์๊ณผ ๊ฐ์ด ๋ฏธ๋ฆฌ ์๋ฌ๋ฅผ ์ก์์ฃผ๊ธฐ ๋๋ฌธ์ด๋ค.

strictFunctionTypes
ํ์ ์คํฌ๋ฆฝํธ๋ ๊ธฐ๋ณธ์ ์ผ๋ก ๊ณต๋ณ์ (covariant)์ธ ๊ท์น์ ๋ฐ๋ฅด์ง๋ง, ํจ์์ ๋งค๊ฐ๋ณ์ ๋ง์ด ์ด๋ณ๋(bivariant)์ ๊ตฌ์กฐ๋ฅผ ๊ฐ์ง๋ค. ๋ฐ๋ผ์ ๋งค๊ฐ๋ณ์ ํ์ ์ด ๋ฌ๋ผ๋ ๋ง ๋์ ํ ์ ์๋ ํ์์ด ์ผ์ด๋๊ฒ ๋๋๋ฐ, ์ด๋ฅผ ๋ฐ๊ณต๋ณ์ (contravariant)์ผ๋ก ์ค์ ํด์ฃผ์ด ์ด๋ณ์ฑ์ ์ค๋ฅ๋ฅผ ํด๊ฒฐํ๋ค. ํ์ง๋ง ์๋ฐ์คํฌ๋ฆฝํธ์์ ์๋ก์ ์ฝ๋ฐฑ์ ํจ์์ ์ธ์๋ก ์ ๋ฌํ๋ ์ผ์ด ๋น๋ฒํ๊ธฐ ๋๋ฌธ์ ์คํ๋ ค ์ด๋ฐ ์ต์ ์ด ํ์ฑํ ๋์๋๊ฒ ๊ฑฐ์ฌ๋ฆด์ ์๋๋ฐ, ์ด ์ต์ ์ false๋ก ํ๋ฉด ๋ฐ๊ณต๋ณ์ฑ์ ๋์ ์๋ค.
"compilerOptions": {
"strict": true,
"strictFunctionTypes": false, /* ์๊ฒฉํ ํจ์ ์ ํ ๊ฒ์ฌ ์ฌ์ฉ */
}
function fn(x: string) {
console.log('Hello, ' + x.toLowerCase());
}
type StringOrNumberFunc = (ns: string | number) => void;
// Unsafe assignment
let func: StringOrNumberFunc = fn; // ๋์
์ด ๊ฐ๋ฅํด์ง๋ค.
func(10); // Unsafe call - will crash

strictPropertyInitialization
์ ์๋์ง ์์ ํด๋์ค์ ์์ฑ์ด ์์ฑ์์์ ์ด๊ธฐํ๋์๋์ง ํ์ธํ๋ค.
์๋ฅผ ๋ค์ด UserAccount ํด๋์ค์ constructor์์๋ name ํ๋กํผํฐ๋ง ์ด๊ธฐํํด์ฃผ๊ณ email ํ๋กํผํฐ๋ ์ ์ธ๋ง ํ์๋๋ฐ, ์ด๋ ๋๋ฌด ๊ฐํ๊ฒ ํ์ ์ฒดํน ํ๋ ๋๋์ด ๋ ๋ค๋ฉด, ์ด ์ต์ ์ false๋ก ์ค์ ๋นจ๊ฐ์ค์ ํด๊ฒฐํ ์ ์๋ค.
"compilerOptions": {
"strict": true,
"strictPropertyInitialization": false, /* ํด๋์ค์์ ์์ฑ ์ด๊ธฐํ ์๊ฒฉ ๊ฒ์ฌ ์ฌ์ฉ */
}
class UserAccount {
name: string;
accountType = 'user';
address: string | undefined;
email: string; // strictPropertyInitialization: false๋ก ํ๋ฉด ๋นจ๊ฐ์ค์ด ์ฌ๋ผ์ง๋ค.
constructor(name: string) {
this.name = name;
}
}

tsconfig๋ฅผ ์์ ํ๋๊ฒ ๋ง์์ ์๋ค๋ฉด, non-null ๋จ์ธ ์ฐ์ฐ์๋ฅผ ์ด์ฉํด๋ ํด๊ฒฐ ํ ์ ์๋ค.
email!: string; // ์ด๋์ ๊ฐ ํ ๋น๋ ๊ฒ์ด๋ฏ๋ก ์๋ฌ๋ฅผ ๋ฌด์ํ๋ผ๋ ์๋ฏธ
strictBindCallApply
function์ ๋ด์ฅ ํจ์์ธ bind, call, apply๋ฅผ ์ฌ์ฉํ ๋ ๋์ฑ ์๊ฒฉํ๊ฒ ๊ฒ์ฌํ๋ ์ต์ ์ด๋ค.
"compilerOptions": {
"strict": true,
"strictBindCallApply": false, /* ์๊ฒฉํ 'bind', 'call', 'apply' ํจ์ ๋ฉ์๋ ์ฌ์ฉ */
}
function fn(x: string) {
return parseInt(x);
}
const n1 = fn.call(undefined, '10');
const n2 = fn.call(undefined, false); // strictBindCallApply: false ๋ก ํ๋ฉด ์๋ฌด๊ฑฐ๋ ๋ฃ์ ์ ์๋ค.

alwaysStrict
์ปดํ์ผ๋ ์๋ฐ์คํฌ๋ฆฝํธ ํ์ผ์ "use strict" ๋ชจ๋๋ฅผ ์ฌ์ฉํ๋๋ก ๋ช ์ํ๋ค. strict ์ต์ ์ด ํ์ฑํ ๋์ด์์๊ฒฝ์ฐ ๊ธฐ๋ณธ์ ์ผ๋ก ์ด ์ต์ ๋ ํ์ฑํ ๋๋ฉฐ, ๋ง์ผ ์ด ์ต์ ์ false๋ก ์ง์ ํ๋ฉด ์ปดํ์ผ๋ ์๋ฐ์คํฌ๋ฆฝํธ ํ์ผ์์ strict mode๋ฅผ ์ฐ์ง ์๊ฒ ๋๋ค.
"compilerOptions": {
"strict": true,
"alwaysStrict": false, /* ์๊ฒฉ๋ชจ๋์์ ๊ตฌ๋ฌธ ๋ถ์ ํ, ๊ฐ ์์ค ํ์ผ์ "use strict" ์ฝ๋๋ฅผ ์ถ๋ ฅ */
}
์ด ๋ฐ์ strict ์์ฑ์ ๊ตญํ๋์ง ์์ ๋ ๋ฆฝ์ ์ธ ์ถ๊ฐ ๊ฒ์ฌ ์ต์ ๋ค์ด๋ค.
noUnusedLocals
์ฐ์ง์๋ ์ง์ญ๋ณ์ ์์ผ๋ฉด ์๋ฌ๋ด๊ธฐ
noUnusedParameters
์ฐ์ง์๋ ํ๋ผ๋ฏธํฐ ์์ผ๋ฉด ์๋ฌ๋ด๊ธฐ
noImplicitReturns
ํจ์์์ return ๋นผ๋จน์ผ๋ฉด ์๋ฌ๋ด๊ธฐ
noFallthroughCasesInSwitch
switch๋ฌธ ์ด์ํ๋ฉด ์๋ฌ๋ด๊ธฐ. ์๋ฅผ๋ค์ด switch ๋ฌธ์์ ๋น์ด ์์ง ์์ Case๋ผ๋ฉด ๋ฐ๋์ break ๋ฌธ์ด๋ return ๋ฌธ์ผ๋ก ํด๋น Case๋ฅผ ์ข ๋ฃ์ํค๋๋ก ์๋ฌ๋ฅผ ๋ด์ค๋ค. ์ด๋ฅผ ํตํด ์๋์น ์์ Fallthrough Case์ ์ํ ๋ฒ๊ทธ๋ฅผ ์๋ฐฉํ ์ ์๋ค.
Completeness ์ต์
skipLibCheck
ํ์ ์ฒดํน์ ์คํตํ๋๋ก ํ๋ ์ค์ ์ด๋ค. ํ์ ์คํฌ๋ฆฝํธ์ ํ์ ์ฒดํน์ ์ํ๋ฉด ๋ฌด์จ ์๋ฏธ๊ฐ ์๊ฒ ๋ ์ถ์ง๋ง, ๋ง์ผ ํ๋ก์ ํธ์ ๊ท๋ชจ๊ฐ ํฌ๋ฉด ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ์ ์ธ ํ์ผ๋ค์ด ๋งค์ฐ ๋ฐฉ๋ํ ํ ๋ฐ, ๊ทธ๊ฒ๋ค์ ๋งค๋ฒ ๋ค์ ์ฒดํฌํ๋ ๊ฒ์ ์๋นํ ์๊ฐ์ด ์๋ชจ๊ฐ ๋๋ค. ๊ทธ๋์ ์ด ์ต์ ์ true๋ก ์ง์ ํ์ฌ ์ ์ธ ํ์ผ๋ค์ ํ์ ์ฒดํฌ๋ฅผ ์๋ตํ๋๋ก ํ์ฌ ์ปดํ์ผ ์๊ฐ์ ์ค์ฌ์ฃผ๋๋ก ํ๊ธฐ ์ํ ์์ฑ์ด๋ค.
"compilerOptions": {
"skipLibCheck": true, /* ์ ์ธ ํ์ผ ์ ํ ๊ฒ์ฌ ์คํต */
}
# ์ฐธ๊ณ ์๋ฃ
https://it-eldorado.tistory.com/128
https://typescript-kr.github.io/pages/tsconfig.json.html
https://codingapple.com/unit/typescript-tsconfig-json/
https://velog.io/@milkcoke/Typescript-.d.ts-%EC%A0%95%EC%9D%98%ED%95%98%EA%B8%B0
์ด ๊ธ์ด ์ข์ผ์ จ๋ค๋ฉด ๊ตฌ๋ & ์ข์์
์ฌ๋ฌ๋ถ์ ๊ตฌ๋
๊ณผ ์ข์์๋
์ ์์๊ฒ ํฐ ํ์ด ๋ฉ๋๋ค.