Typescript: 2 ์ปดํŒŒ์ผ ์˜ค๋ฅ˜ ๋ฐœ์ƒ

์— ๋งŒ๋“  2018๋…„ 10์›” 25์ผ  ยท  1๋…ผํ‰  ยท  ์ถœ์ฒ˜: microsoft/TypeScript

์˜ˆ์ƒ๋˜๋Š” ๋™์ž‘ :
๋‚ด ์ฝ”๋“œ๊ฐ€ ์˜ค๋ฅ˜์—†์ด ์ปดํŒŒ์ผ ๋  ๊ฒƒ์œผ๋กœ ์˜ˆ์ƒํ•ฉ๋‹ˆ๋‹ค.
๊ทธ๋ฆฌ๊ณ  import ๋ฌธ์ด ์ž‘๋™ํ•˜๊ธฐ๋ฅผ ๊ธฐ๋Œ€ํ•ฉ๋‹ˆ๋‹ค.

์‹ค์ œ ํ–‰๋™ :
tsc app.ts๋ฅผ ์‹คํ–‰ํ•  ๋•Œ ๋‹ค์Œ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.
../node_modules/@types/bluebird/index.d.ts:750:72-์˜ค๋ฅ˜ TS2583 : 'Map'์ด๋ฆ„์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ํƒ€๊ฒŸ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ๋ณ€๊ฒฝํ•ด์•ผํ•ฉ๋‹ˆ๊นŒ? lib ์ปดํŒŒ์ผ๋Ÿฌ ์˜ต์…˜์„ es2015 ์ด์ƒ์œผ๋กœ ๋ณ€๊ฒฝํ•ด๋ณด์‹ญ์‹œ์˜ค.

750 ์ •์  ์†Œํ’ˆ(์ง€๋„ : ํ•ด๊ฒฐ ๊ฐ€๋Šฅ>>) : ๋ธ”๋ฃจ ๋ฒ„๋“œ>;
ํ”Œ๋ ˆ์ด ๊ทธ๋ผ์šด๋“œ ๋งํฌ :

์ฝ”๋“œ ํŽธ์ง‘๊ธฐ์—์„œ ๋˜ ๋‹ค๋ฅธ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.
'/Users/harry.gothold/Documents/api-call-weather/src/app.ts'ํŒŒ์ผ์€ ๋ชจ๋“ˆ์ด ์•„๋‹™๋‹ˆ๋‹ค.

์ด๊ฒƒ์€ ๋‚ด๊ฐ€ ์‹คํ–‰ํ•˜๋ ค๋Š” ํ…Œ์ŠคํŠธ์ž…๋‹ˆ๋‹ค.
`
import * as app from '../src/app';
// 'chai'์—์„œ *๋ฅผ chai๋กœ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค.
// '../app'์—์„œ {๊ฒฐ๊ณผ} ๊ฐ€์ ธ ์˜ค๊ธฐ;
var chai = require ( 'chai');
var sinon = require ( 'sinon');
const ๊ธฐ๋Œ€ = chai.expect;

describe ( 'result', function () {
it ( 'should with weatherDescription', (done) => {
expect (result) .to.eventually.equal ( '๋ง‘์€ ํ•˜๋Š˜');
๋๋‚œ();
});
});`

๋‹ค์Œ์€ ์›๋ž˜ TS ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค.
`let request = require ( 'request');
์•ฝ์†ํ•˜์ž = require ( 'bluebird');

function getData () {
return new promise ((resolve : any, reject : any) => {
request ( 'https://api.openweathermap.org/data/2.5/forecast?id=2643743&APPID=99eaec08987344591490f9a6ee213155', {json : true},
(err : any, res : any, body : any) => {
resolve (body.list [0] .weather [0] .description);
reject (err, '์ฃ„์†กํ•ฉ๋‹ˆ๋‹ค. ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ ์˜ค๋Š” ๋™์•ˆ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.');
});
});
};

function result (weatherDescription : any) {
console.log ( The weather today is ${weatherDescription} );
}

getData ()
.then ((weatherDescription : any) => {
๊ฒฐ๊ณผ (๋‚ ์”จ ์„ค๋ช…)
})
.catch ((err : any) => {
๋˜์ง€๋‹ค (err)
});

module.exports = {
getData : function () {},
๊ฒฐ๊ณผ : function () {}
}`

๊ทธ๋ฆฌ๊ณ  ์ด๊ฒƒ์€ ๋‚ด tsconfig ํŒŒ์ผ์ž…๋‹ˆ๋‹ค.
`{
"compilerOptions": {
/ * ๊ธฐ๋ณธ ์˜ต์…˜ /"target": "es6", / ECMAScript ๋Œ€์ƒ ๋ฒ„์ „ ์ง€์ • : 'ES3'(๊ธฐ๋ณธ๊ฐ’), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018'๋˜๋Š” 'ESNEXT'. /"module": "commonjs", / ๋ชจ๋“ˆ ์ฝ”๋“œ ์ƒ์„ฑ ์ง€์ • : 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015'๋˜๋Š” 'ESNext'. /"lib": [ "es5", "es6", "dom"], / ์ปดํŒŒ์ผ์— ํฌํ•จ ํ•  ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ํŒŒ์ผ์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค. /// "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": "./", / ์ž…๋ ฅ ํŒŒ์ผ์˜ ๋ฃจํŠธ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค. --outDir๋กœ ์ถœ๋ ฅ ๋””๋ ‰ํ† ๋ฆฌ ๊ตฌ์กฐ๋ฅผ ์ œ์–ดํ•˜๋Š” โ€‹โ€‹๋ฐ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. /// "composite": true, / ํ”„๋กœ์ ํŠธ ์ปดํŒŒ์ผ ํ™œ์„ฑํ™” /// "removeComments": true, / ์ถœ๋ ฅ์— ์ฃผ์„์„ ํ‘œ์‹œํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. /// "noEmit": true, / ์ถœ๋ ฅ์„ ๋‚ด ๋ณด๋‚ด์ง€ ์•Š์Šต๋‹ˆ๋‹ค. /// "importHelpers": true, / Import๋Š” 'tslib'์—์„œ ๋„์šฐ๋ฏธ๋ฅผ ๋‚ด ๋ณด๋ƒ…๋‹ˆ๋‹ค. /// "downlevelIteration": true, / 'ES5'๋˜๋Š” 'ES3'๋ฅผ ๋Œ€์ƒ์œผ๋กœ ํ•  ๋•Œ 'for-of', ์Šคํ”„๋ ˆ๋“œ ๋ฐ ๋””์ŠคํŠธ ๋Ÿญ์ฒ˜๋ง์—์„œ ์ดํ„ฐ ๋Ÿฌ๋ธ”์„ ์™„๋ฒฝํ•˜๊ฒŒ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค. /// "isolatedModules": true, / ๊ฐ ํŒŒ์ผ์„ ๋ณ„๋„์˜ ๋ชจ๋“ˆ๋กœ ํŠธ๋žœ์Šค ํŒŒ์ผํ•ฉ๋‹ˆ๋‹ค ( 'ts.transpileModule'๊ณผ ์œ ์‚ฌ). * /

/* Strict Type-Checking Options */
"strict": true,                           /* Enable all strict type-checking options. */
// "noImplicitAny": true,                 /* 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. */
// "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. */

}
}`

Question

>๋ชจ๋“  ๋Œ“๊ธ€

์ด์™€ ๊ฐ™์€ ์งˆ๋ฌธ์€ Stack Overflow์— ์ง์ ‘ ๋ฌธ์˜ํ•˜์‹ญ์‹œ์˜ค.

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰