์์๋๋ ๋์ :
๋ด ์ฝ๋๊ฐ ์ค๋ฅ์์ด ์ปดํ์ผ ๋ ๊ฒ์ผ๋ก ์์ํฉ๋๋ค.
๊ทธ๋ฆฌ๊ณ 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. */
}
}`
์ด์ ๊ฐ์ ์ง๋ฌธ์ Stack Overflow์ ์ง์ ๋ฌธ์ํ์ญ์์ค.