250x250
Rainbow๐ŸŒˆCoder
My dev Note๐Ÿ“’
Rainbow๐ŸŒˆCoder
์ „์ฒด ๋ฐฉ๋ฌธ์ž
์˜ค๋Š˜
์–ด์ œ
  • ๋ถ„๋ฅ˜ ์ „์ฒด๋ณด๊ธฐ (411)
    • ๊ณต์ง€์‚ฌํ•ญ (0)
    • Debugger (10)
      • Visual Studio Debugger (1)
      • Chrome DevTools (3)
      • Visual Studio Code Debugger (4)
      • eclipse (1)
      • intelliJ (1)
    • OOP (2)
      • OOP (2)
    • TypeScript (54)
      • ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ TypeScript (54)
    • Javascript (87)
      • Javascript (45)
      • Node.js (19)
      • React (5)
      • FE ๊ฐœ๋ฐœํ™˜๊ฒฝ์„ค์ • (3)
      • React์™€ Node ๊ฐ™์ด ๋•Œ๋ ค์žก๊ธฐ (6)
      • next.js (2)
      • pixi.js (7)
    • ๋งˆํฌ์—… (23)
      • Html & Css (23)
    • C# (80)
      • C# (12)
      • ์ด๊ฒƒ์ด C#์ด๋‹ค (68)
    • C++ (30)
      • c++ (27)
      • win api (3)
    • Unity (18)
      • Unity(๊ธฐ์ดˆ) (8)
      • Unity(C#์ค‘๊ธ‰) (5)
      • ์œ ๋‹ˆํ‹ฐ ํฌํ†ค(๋„คํŠธ์›Œํฌ) (4)
      • unity c# MyCode (1)
    • Java & Spring (29)
      • Java (11)
      • ์Šคํ”„๋ง (8)
      • Java Algorithm (9)
      • Javs Data Structures (1)
    • ์ž๋ฃŒ๊ตฌ์กฐ์™€ ์•Œ๊ณ ๋ฆฌ์ฆ˜ (15)
      • ์ž๋ฃŒ๊ตฌ์กฐ (5)
      • ์•Œ๊ณ ๋ฆฌ์ฆ˜ (10)
    • ํ˜•์ƒ๊ด€๋ฆฌ (15)
      • Git (11)
      • ์†Œ์ŠคํŠธ๋ฆฌ (3)
    • ๊ทธ๋ž˜ํ”ฝ์Šค (7)
      • WebGl (7)
    • AWS (3)
      • aws (3)
    • ๋ฆฌ๋ˆ…์Šค (5)
      • ๋ฆฌ๋ˆ…์Šค (5)
    • ์ฑ… ๋ฆฌ๋ทฐ (13)
      • ํด๋ฆฐ์ฝ”๋“œ(์ฑ…๋ฆฌ๋ทฐ) (3)
      • ์œ ์ง€๋ณด์ˆ˜๊ฐ€๋Šฅํ•œ์ฝ”๋”ฉ์˜๊ธฐ์ˆ C#ํŽธ(์ฑ…๋ฆฌ๋ทฐ) (1)
      • ๋ฆฌํŒฉํ† ๋ง(์ž๋ฐ”์Šคํฌ๋ฆฝํŠธํŒ) (9)
    • Server (2)
      • ๊ฒŒ์ž„ ์„œ๋ฒ„(๋„คํŠธ์›Œํฌ, ๋ฉ€ํ‹ฐ์“ฐ๋ ˆ๋“œ,OS) (2)
    • ์„ค๊ณ„, ์•„ํ‚คํ…์ณ (4)
    • ํŒŒ์ด์ฌ (5)
    • ๋””์ž์ธํŒจํ„ด (2)
    • mocha (2)
    • Jest (1)
    • Spine (1)
    • ์ธ๊ณต์ง€๋Šฅ (1)
      • ํ˜ผ์ž๊ณต๋ถ€ํ•˜๋Š”๋จธ์‹ ๋Ÿฌ๋‹+๋”ฅ๋Ÿฌ๋‹ (1)

๋ธ”๋กœ๊ทธ ๋ฉ”๋‰ด

  • ํ™ˆ
  • ํƒœ๊ทธ
  • ๋ฐฉ๋ช…๋ก

๊ณต์ง€์‚ฌํ•ญ

์ธ๊ธฐ ๊ธ€

ํƒœ๊ทธ

  • ์œ„์ž„
  • MySQL
  • ใ…ฃใ„ท
  • ์ปดํฌ์ง€์…˜

์ตœ๊ทผ ๋Œ“๊ธ€

์ตœ๊ทผ ๊ธ€

ํ‹ฐ์Šคํ† ๋ฆฌ

hELLO ยท Designed By ์ •์ƒ์šฐ.
Rainbow๐ŸŒˆCoder

My dev Note๐Ÿ“’

TypeScript/ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ TypeScript

[ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ] ์—ฐ์Šต์šฉ์œผ๋กœ ์ž์ฃผ ์‚ฌ์šฉํ•˜๋Š” ์„ธํŒ…

2022. 4. 27. 01:27
728x90

์„ค์น˜์™€ ๋ณ€ํ™˜ ํ•œ์ค„ ์š”์•ฝ

node.js ์„ค์น˜ → npm i -g typescript → tsconfig.json ์ƒ์„ฑ → tsc -w

<์š”์•ฝ>
 ts๋Š” ๋ธŒ๋ผ์šฐ์ €์—์„œ๋„ node์—์„œ๋„ ์ฝํžˆ์ง€ ์•Š๋Š”๋‹ค.

ts๋Š” js ์ฝ”๋“œ๋กœ ๋ณ€ํ™˜ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค. index.ts๋ฅผ ๋งŒ๋“ค์—ˆ๋‹ค๋ฉด

tsc index.ts ๋ž€ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅ main.js๋ž€ ํŒŒ์ผ์ด ์ƒˆ๋กœ ์ƒ์„ฑ๋œ๋‹ค.

์ด ๋ณ€ํ™˜๋œ js๋Š” ์ด์ œ ๋ธŒ๋ผ์šฐ์ €๋‚˜ node์—์„œ ์ฝ์„ ์ˆ˜ ์žˆ๋‹ค.

ts๋ฅผ js๋กœ ๋งค๋ฒˆ ์ˆ˜๋™ ๋ณ€ํ™˜

tsc ํŒŒ์ผ๋ช….ts

 

๋…ธ๋“œ์—์„œ ๊ฐ„ํŽธํ•˜๊ฒŒ ์‹คํ–‰

ts-node ์„ค์น˜ ๋ช…๋ น์–ด: ๋‚ด๋ถ€์ ์œผ๋กœ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ ์ฝ”๋“œ๋ฅผ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์ฝ”๋“œ๋กœ ๋ณ€ํ™˜ํ•ด์„œ ๋…ธ๋“œ์—์„œ ์‹คํ–‰ํ•˜๋Š” ๊ฒƒ์„ ํ•œ๋ฒˆ์— ํ•  ์ˆ˜ ์žˆ๋„๋ก ๋„์™€์ฃผ๋Š” ํˆด

npm install -g ts-node ์„ค์น˜ ํ›„

๊ฐ€๋ น index.ts๋ฅผ ์‹คํ–‰ํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด 

ts-node index.ts ๋งŒ ์จ์ฃผ๋ฉด ๋œ๋‹ค.

ts-node src/index.ts (ํด๋”์— ์žˆ๋Š” ๊ฒฝ์šฐ)

 

๋ธŒ๋ผ์šฐ์ €์—์„œ ๊ฐ„ํŽธํ•˜๊ฒŒ ์‹คํ–‰

tsc ํŒŒ์ผ๋ช….ts -w
Watch mode
๋งค๋ฒˆ ๋ณ€ํ™”๊ฐ€ ์žˆ์„ ๋•Œ๋งˆ๋‹ค tsc๋ช…๋ น์–ด๋กœ TypeScript ์ปดํŒŒ์ผ์„ ํ•ด์ฃผ๋Š” ๊ฒƒ ๋Œ€์‹ ์—, watch mode๋กœ ์ปดํŒŒ์ผ์„ ์‹œ์ž‘ํ•˜๋ฉด  TypeScript ํŒŒ์ผ ์ €์žฅ ํ›„, ์ €์žฅ ์ „๊ณผ ๋ณ€ํ™”๊ฐ€ ์žˆ์„ ๋•Œ๋งˆ๋‹ค ์ž๋™ ์ปดํŒŒ์ผ ํ•ด์ค€๋‹ค.
$ tsc -w
ํ„ฐ๋ฏธ๋„์ด ๊ณ„์† watching… ts๋ฅผ ๋ฐ”๋ผ๋ณธ๋‹ค๋Š” ์˜๋ฏธ์ด๋‹ค.

 


 

ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ ํ”„๋กœ์ ํŠธ ๋งŒ๋“ค๊ธฐ : ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ ํ”„๋กœ๊ทธ๋ž˜๋ฐ(์ถœํŒ์‚ฌ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์ธ์‚ฌ์ดํŠธ)๋™์ผํ•˜๊ฒŒ ๊ตฌ์„ฑ


์ฝ”๋“œ ํŽธ์ง‘๊ธฐ ์„ค์ •


์˜ˆ๋น„๋‹จ๊ณ„1. NodeJs

TSC ์ž์ฒด๋„ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ๋กœ ๊ตฌํ˜„๋œ ๋ช…๋ นํ–‰ ๋„๊ตฌ์ด๋ฏ€๋กœ TSC๋ฅผ ์‹คํ–‰ํ•˜๋ ค๋ฉด NodeJS๊ฐ€ ํ•„์š”ํ•˜๋‹ค.(์ด๋Ÿฐ ์ด์œ ๋กœ TSC๋Š” ์ž์ฒด ํ˜ธ์ŠคํŒ… ์ปดํŒŒ์ผ๋Ÿฌ ๋˜๋Š” ์ž์‹ ์„ ์ปดํŒŒ์ผํ•˜๋Š” ์ปดํŒŒ์ผ๋Ÿฌ๋ผ๋Š” ํŠน๋ณ„ํ•œ ์ข…๋ฅ˜์˜ ์ปดํŒŒ์ผ๋Ÿฌ๊ฐ€ ๋œ๋‹ค.)

NodeJs๋Š” ํ”„๋กœ์ ํŠธ์˜ ์˜์กด์„ฑ์ด๋‚˜ ๋นŒ๋“œ๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ํŒจํ‚ค์ง€ ๊ด€๋ฆฌ์ž NPM์„ ํฌํ•จํ•œ๋‹ค. NPM์„ ์ด์šฉํ•ด TSC์™€ TSLint๋ฅผ ์„ค์น˜ํ•  ๊ฒƒ์ด๋‹ค.

1.
ํ„ฐ๋ฏธ๋„ ์ฐฝ์„ ์—ด์–ด ์ƒˆ ๋””๋ ‰ํ„ฐ๋ฆฌ๋ฅผ ๋งŒ๋“ค๊ณ  ๊ทธ ์•ˆ์— ์ƒˆ npm ํ”„๋กœ์ ํŠธ๋ฅผ ์ดˆ๊ธฐํ™”ํ•œ๋‹ค.

mkdir chapter-2

cd chapter-2 

npm init -y : ์ƒˆ NPM ํ”„๋กœ์ ํŠธ ์ดˆ๊ธฐํ™”

npm install --save-dev typescript tslint @types/node : TSC,TSLint, NodeJS์šฉ ํƒ€์ž… ์„ ์–ธ ์„ค์น˜ 


$ npm install --save-dev typescript tslint @types/node
npm WARN deprecated tslint@6.1.3: TSLint has been deprecated in favor of ESLint. Please see https://github.com/palantir/tslint/issues/4534 for more information.

added 43 packages, and audited 44 packages in 8s

4 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
2. 
๋ชจ๋“  ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ ํ”„๋กœ์ ํŠธ๋Š” ๋ฃจํŠธ ๋””๋ ‰ํ„ฐ๋ฆฌ์— tsconfig.json ์ด๋ผ๋Š” ํŒŒ์ผ์ด ์กด์žฌํ•ด์•ผ ํ•œ๋‹ค.

ํƒ€์ž… ์Šคํฌ๋ฆฝํŠธ ํ”„๋กœ์ ํŠธ์—์„œ ์–ด๋–ค ํŒŒ์ผ์„ ์ปดํŒŒ์ผํ•˜๊ณ , ์–ด๋–ค ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๋ฒ„์ „์œผ๋กœ ๋ฐฉ์ถœํ•˜๋Š”์ง€ ๋“ฑ์„ ์ •์˜ํ•œ๋‹ค.

 

./node_modules/.bin/tsc --init

--init ํ”Œ๋ž˜๊ทธ์™€ ํ•จ๊ป˜ tsc๋ฅผ ์‹คํ–‰ํ•œ ํ›„, tsconfig.json ํŒŒ์ผ์ด ๋ช‡ ๊ฐ€์ง€ ๊ธฐ๋ณธ ๊ฐ’๋“ค๊ณผ ํ•จ๊ป˜ ํ”„๋กœ์ ํŠธ ํด๋”์— ์ƒ๊ฒผ๋‹ค.

tsconfig.json


{
  "compilerOptions": {
    /* Visit https://aka.ms/tsconfig.json to read more about this file */

    /* Projects */
    // "incremental": true,                              /* Enable incremental compilation */
    // "composite": true,                                /* Enable constraints that allow a TypeScript project to be used with project references. */
    // "tsBuildInfoFile": "./",                          /* Specify the folder for .tsbuildinfo incremental compilation files. */
    // "disableSourceOfProjectReferenceRedirect": true,  /* Disable preferring source files instead of declaration files when referencing composite projects */
    // "disableSolutionSearching": true,                 /* Opt a project out of multi-project reference checking when editing. */
    // "disableReferencedProjectLoad": true,             /* Reduce the number of projects loaded automatically by TypeScript. */

    /* Language and Environment */
    "target": "es2016",                                  /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
    // "lib": [],                                        /* Specify a set of bundled library declaration files that describe the target runtime environment. */
    // "jsx": "preserve",                                /* Specify what JSX code is generated. */
    // "experimentalDecorators": true,                   /* Enable experimental support for TC39 stage 2 draft decorators. */
    // "emitDecoratorMetadata": true,                    /* Emit design-type metadata for decorated declarations in source files. */
    // "jsxFactory": "",                                 /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */
    // "jsxFragmentFactory": "",                         /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
    // "jsxImportSource": "",                            /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */
    // "reactNamespace": "",                             /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */
    // "noLib": true,                                    /* Disable including any library files, including the default lib.d.ts. */
    // "useDefineForClassFields": true,                  /* Emit ECMAScript-standard-compliant class fields. */

    /* Modules */
    "module": "commonjs",                                /* Specify what module code is generated. */
    // "rootDir": "./",                                  /* Specify the root folder within your source files. */
    // "moduleResolution": "node",                       /* Specify how TypeScript looks up a file from a given module specifier. */
    // "baseUrl": "./",                                  /* Specify the base directory to resolve non-relative module names. */
    // "paths": {},                                      /* Specify a set of entries that re-map imports to additional lookup locations. */
    // "rootDirs": [],                                   /* Allow multiple folders to be treated as one when resolving modules. */
    // "typeRoots": [],                                  /* Specify multiple folders that act like `./node_modules/@types`. */
    // "types": [],                                      /* Specify type package names to be included without being referenced in a source file. */
    // "allowUmdGlobalAccess": true,                     /* Allow accessing UMD globals from modules. */
    // "resolveJsonModule": true,                        /* Enable importing .json files */
    // "noResolve": true,                                /* Disallow `import`s, `require`s or `<reference>`s from expanding the number of files TypeScript should add to a project. */

    /* JavaScript Support */
    // "allowJs": true,                                  /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */
    // "checkJs": true,                                  /* Enable error reporting in type-checked JavaScript files. */
    // "maxNodeModuleJsDepth": 1,                        /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */

    /* Emit */
    // "declaration": true,                              /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
    // "declarationMap": true,                           /* Create sourcemaps for d.ts files. */
    // "emitDeclarationOnly": true,                      /* Only output d.ts files and not JavaScript files. */
    // "sourceMap": true,                                /* Create source map files for emitted JavaScript files. */
    // "outFile": "./",                                  /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
    // "outDir": "./",                                   /* Specify an output folder for all emitted files. */
    // "removeComments": true,                           /* Disable emitting comments. */
    // "noEmit": true,                                   /* Disable emitting files from a compilation. */
    // "importHelpers": true,                            /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
    // "importsNotUsedAsValues": "remove",               /* Specify emit/checking behavior for imports that are only used for types */
    // "downlevelIteration": true,                       /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
    // "sourceRoot": "",                                 /* Specify the root path for debuggers to find the reference source code. */
    // "mapRoot": "",                                    /* Specify the location where debugger should locate map files instead of generated locations. */
    // "inlineSourceMap": true,                          /* Include sourcemap files inside the emitted JavaScript. */
    // "inlineSources": true,                            /* Include source code in the sourcemaps inside the emitted JavaScript. */
    // "emitBOM": true,                                  /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
    // "newLine": "crlf",                                /* Set the newline character for emitting files. */
    // "stripInternal": true,                            /* Disable emitting declarations that have `@internal` in their JSDoc comments. */
    // "noEmitHelpers": true,                            /* Disable generating custom helper functions like `__extends` in compiled output. */
    // "noEmitOnError": true,                            /* Disable emitting files if any type checking errors are reported. */
    // "preserveConstEnums": true,                       /* Disable erasing `const enum` declarations in generated code. */
    // "declarationDir": "./",                           /* Specify the output directory for generated declaration files. */
    // "preserveValueImports": true,                     /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */

    /* Interop Constraints */
    // "isolatedModules": true,                          /* Ensure that each file can be safely transpiled without relying on other imports. */
    // "allowSyntheticDefaultImports": true,             /* Allow 'import x from y' when a module doesn't have a default export. */
    "esModuleInterop": true,                             /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */
    // "preserveSymlinks": true,                         /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
    "forceConsistentCasingInFileNames": true,            /* Ensure that casing is correct in imports. */

    /* Type Checking */
    "strict": true,                                      /* Enable all strict type-checking options. */
    // "noImplicitAny": true,                            /* Enable error reporting for expressions and declarations with an implied `any` type.. */
    // "strictNullChecks": true,                         /* When type checking, take into account `null` and `undefined`. */
    // "strictFunctionTypes": true,                      /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
    // "strictBindCallApply": true,                      /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */
    // "strictPropertyInitialization": true,             /* Check for class properties that are declared but not set in the constructor. */
    // "noImplicitThis": true,                           /* Enable error reporting when `this` is given the type `any`. */
    // "useUnknownInCatchVariables": true,               /* Type catch clause variables as 'unknown' instead of 'any'. */
    // "alwaysStrict": true,                             /* Ensure 'use strict' is always emitted. */
    // "noUnusedLocals": true,                           /* Enable error reporting when a local variables aren't read. */
    // "noUnusedParameters": true,                       /* Raise an error when a function parameter isn't read */
    // "exactOptionalPropertyTypes": true,               /* Interpret optional property types as written, rather than adding 'undefined'. */
    // "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 */
    // "noImplicitOverride": true,                       /* Ensure overriding members in derived classes are marked with an override modifier. */
    // "noPropertyAccessFromIndexSignature": true,       /* Enforces using indexed accessors for keys declared using an indexed type */
    // "allowUnusedLabels": true,                        /* Disable error reporting for unused labels. */
    // "allowUnreachableCode": true,                     /* Disable error reporting for unreachable code. */

    /* Completeness */
    // "skipDefaultLibCheck": true,                      /* Skip type checking .d.ts files that are included with TypeScript. */
    "skipLibCheck": true                                 /* Skip type checking all .d.ts files. */
  }
}

ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ ํ”„๋กœ๊ทธ๋ž˜๋ฐ(์ถœํŒ์‚ฌ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์ธ์‚ฌ์ดํŠธ)๊ณผ ๋™์ผํ•˜๊ฒŒ ๊ตฌ์„ฑ(tsconfig.json ๋ฅผ ์ง์ ‘ ๋งŒ๋“ค์–ด์„œ ์•„๋ž˜์™€ ๊ฐ™์ด ์ž‘์„ฑํ•ด๋„ ๋œ๋‹ค)


{
  "compilerOptions": {
    "lib": ["es2015"],
    "module": "commonjs",
    "outDir": "dist",
    "sourceMap": true,
    "strict": true,
    "target": "es2015"
  },
  "include": ["src"]
}
๊ฐ ์นดํ…Œ๊ณ ๋ฆฌ ์„ค๋ช…:

{
  "compilerOptions": {         
    "lib": ["es2015"],                TSC๊ฐ€ ์ฝ”๋“œ ์‹คํ–‰ ํ™˜๊ฒฝ์—์„œ ์ด์šฉํ•  ์ˆ˜ ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•˜๋Š” API
    "module": "commonjs",     TSC๊ฐ€ ์ฝ”๋“œ๋ฅผ ์ปดํŒŒ์ผํ•  ๋Œ€์ƒ ๋ชจ๋“ˆ ์‹œ์Šคํ…œ(CommonJS, SystemJS, ES2015 ๋“ฑ)
    "outDir": "dist",                  ์ƒ์„ฑ๋œ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์ฝ”๋“œ๋ฅผ ์ถœ๋ ฅํ•  ๋””๋ ‰ํ„ฐ๋ฆฌ
    "sourceMap": true,           ์†Œ์Šค ๋งต(Source Map)์ด๋ž€ ๋ฐฐํฌ์šฉ์œผ๋กœ ๋นŒ๋“œํ•œ ํŒŒ์ผ๊ณผ ์›๋ณธ ํŒŒ์ผ์„ ์„œ๋กœ ์—ฐ๊ฒฐ์‹œ์ผœ์ฃผ๋Š” ๊ธฐ๋Šฅ
    "strict": true, ๊ฐ•๋ ฅ์ถ”์ฒœ  ์œ ํšจํ•˜์ง€ ์•Š์€ ์ฝ”๋“œ๋ฅผ ํ™•์ธํ•  ๋•Œ ๊ฐ€๋Šฅํ•œ ์—„๊ฒฉํ•˜๊ฒŒ ๊ฒ€์‚ฌ ์ฝ”๋“œ๊ฐ€ ์ ์ ˆ ํƒ€์ž…์„ ๊ฐ–์ถ”๋„๋ก ๊ฐ•์ œ
    "target": "es2015"            ์–ด๋–ค ๋ฒ„์ „์˜ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋กœ ์ปดํŒŒ์ผ ๋˜๊ณ  ์‹ถ์€ ์ง€
  },
  "include": ["src"]               TSC[]๊ฐ€ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ ํŒŒ์ผ์„ ์ฐพ์„ ๋””๋ ‰ํ„ฐ๋ฆฌ๋กœ, ์–ด๋–ค ํŒŒ์ผ๋“ค์ด ์ปดํŒŒ์ผ ๊ณผ์ •์— ํฌํ•จ๋˜๋Š”์ง€ TSC์—๊ฒŒ ์•Œ๋ ค์ฃผ๋Š” ๋ถ€๋ถ„, ์ปดํŒŒ์ผ ๊ณผ์ •์—์„œ ํฌํ•จํ•  ํŒŒ์ผ์˜ ๋ฐฐ์—ด []์„ ์ ์œผ๋ฉด ๋œ๋‹ค.
} 

 

3. 
TSLint๋Š” ์„ ํƒ์‚ฌํ•ญ์ด์ง€๋งŒ,

๋ณดํ†ต ํ”„๋กœ์ ํŠธ๋Š” TSLint ์„ค์ •์„ ์ •์˜ํ•˜๋Š” tslint.json ํŒŒ์ผ๋„ ํฌํ•จํ•œ๋‹ค. ๋ชจ๋“  TS ํ”„๋กœ์ ํŠธ์— ์ผ๊ด€๋œ ์ฝ”๋”ฉ ์Šคํƒ€์ผ(ํƒญ, ๊ณต๋ฐฑ ๋“ฑ…)์„ ์‚ฌ์šฉํ•˜๋„๋ก ๊ฐ•๋ ฅ ๊ถŒ์žฅํ•ด์ค€๋‹ค. ์ฝ”๋“œ๋ฆฌ๋ทฐ ์‹œ๊ฐ„์ด ์งง์•„์ง„๋‹ค.

./node_modules/.bin/tslint --init : ๋””ํดํŠธ tslint.json ํŒŒ์ผ ์ƒ์„ฑ ๋ช…๋ น์–ด

tslint.json


{
    "defaultSeverity": "error",
    "extends": [
        "tslint:recommended"
    ],
    "jsRules": {},
    "rules": {},
    "rulesDirectory": []
}
๋งŒ๋“ค์–ด์ง„ ํŒŒ์ผ์€ ์ž์‹ ์˜ ์ฝ”๋”ฉ ์Šคํƒ€์ผ์— ๋งž๊ฒŒ ํŽธ์ง‘ํ•  ์ˆ˜ ์žˆ๋‹ค.

์ €์ž์™€ ๋˜‘๊ฐ™์ด ํŽธ์ง‘


{
  "defaultSeverity": "error",
  "extends": ["tslint:recommended"],
  "rules": {
    "semicolon": false,
    "trailing-comma": false
  }
}
4.
 ์ด์ œ src ๋””๋ ‰ํ„ฐ๋ฆฌ์— index.ts๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค.

index.ts


console.log("Hello Ts!");
 


tsc ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•ด ์ปดํŒŒ์ผ


#TSC๋กœ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ ์ปดํŒŒ์ผ
./node_modules/.bin/tsc
#NodeJS๋กœ ์ฝ”๋“œ ์‹คํ–‰
node ./dist/index.js
 


์ด์ œ JavaScript ํŒŒ์ผ๊ณผ .map ํŒŒ์ผ์ด ์ƒ์„ฑ๋˜์—ˆ๋‹ค.

index.js


"use strict";
console.log("Hello Ts!");
//# sourceMappingURL=index.js.map

index.js.map


{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC"}
 

<์—ฐ์Šต๋ฌธ์ œ>

ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ ํƒ€์ž… ์ถ”๋ก ํ™•์ธ : 


let a = 1 + 2; //number
let b = a + 3; //number
let c = {
  apple: a,
  banana: b,
};
//let c = {
//  apple: a,
//  banana: b,
//}
let d = c.apple * 4; //number

 
 

๋Œ€์ฒด ๊ฐœ์ธ ์—ฐ์Šต ์„ค์ •



npm start ์ž…๋ ฅํ•˜๋ฉด node๋กœ ์‹คํ–‰ํ•˜๊ฒŒ๋”

package.json


{
  "name": "trash",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node dist/index.js",
    "prestart": "tsc"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@types/node": "^17.0.23",
    "tslint": "^6.1.3",
    "typescript": "^4.6.3"
  }
}

tsconfig.json


{
  "compilerOptions": {
    "lib": ["es2015"],
    "module": "commonjs",
    "outDir": "dist",
    "sourceMap": true,
    "strict": true,
    "target": "es2015"
  },
  "include": ["src"],
  "exclude": ["node_modules"]
}

 

728x90

'TypeScript > ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ TypeScript' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ + ๋ฆฌ๋•์Šค  (0) 2022.05.01
[ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ] ํŒฉํ† ๋ฆฌ ํŒจํ„ด  (0) 2022.04.28
[ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ] ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ ์ปดํŒŒ์ผ๋Ÿฌ(Typescript Compiler, TSC)  (0) 2022.04.27
[ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ] ํ•œ์ •๋œ ๋‹คํ˜•์„ฑ, ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์ด์ง„ํŠธ๋ฆฌ ์˜ˆ์ œ ๋ถ„์„  (0) 2022.04.26
[ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ] ํƒ€์ž…๋ณ„์นญ ์ธํ„ฐ์„น์…˜์— ์˜ํ•œ ํ™•์žฅ  (0) 2022.04.26
    'TypeScript/ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ TypeScript' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€
    • ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ + ๋ฆฌ๋•์Šค
    • [ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ] ํŒฉํ† ๋ฆฌ ํŒจํ„ด
    • [ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ] ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ ์ปดํŒŒ์ผ๋Ÿฌ(Typescript Compiler, TSC)
    • [ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ] ํ•œ์ •๋œ ๋‹คํ˜•์„ฑ, ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์ด์ง„ํŠธ๋ฆฌ ์˜ˆ์ œ ๋ถ„์„
    Rainbow๐ŸŒˆCoder
    Rainbow๐ŸŒˆCoder
    ๋ชฐ๋ผ๋„ ๊ฒฐ๊ตญ์€ ์•„๋Š” ๊ฐœ๋ฐœ์ž, ๊ทธ๋Ÿฐ ์‚ฌ๋žŒ์ด ๋˜๊ธฐ ์œ„ํ•œ ๋งค์ผ์˜ ํ•œ๊ฑธ์Œ

    ํ‹ฐ์Šคํ† ๋ฆฌํˆด๋ฐ”