ΠΠΆΠΈΠ΄Π°Π΅ΠΌΠΎΠ΅ ΠΏΠΎΠ²Π΅Π΄Π΅Π½ΠΈΠ΅:
Π― ΠΎΠΆΠΈΠ΄Π°Ρ, ΡΡΠΎ ΠΌΠΎΠΉ ΠΊΠΎΠ΄ Π±ΡΠ΄Π΅Ρ ΠΊΠΎΠΌΠΏΠΈΠ»ΠΈΡΠΎΠ²Π°ΡΡΡΡ Π±Π΅Π· ΠΎΡΠΈΠ±ΠΎΠΊ
Π ΠΎΠΆΠΈΠ΄Π°Ρ, ΡΡΠΎ ΠΎΠΏΠ΅ΡΠ°ΡΠΎΡ ΠΈΠΌΠΏΠΎΡΡΠ° Π±ΡΠ΄Π΅Ρ ΡΠ°Π±ΠΎΡΠ°ΡΡ
Π€Π°ΠΊΡΠΈΡΠ΅ΡΠΊΠΎΠ΅ ΠΏΠΎΠ²Π΅Π΄Π΅Π½ΠΈΠ΅:
ΠΠΎΠ³Π΄Π° Ρ Π·Π°ΠΏΡΡΠΊΠ°Ρ tsc app.ts, Ρ ΠΏΠΎΠ»ΡΡΠ°Ρ ΡΠ°ΠΊΡΡ ββΠΎΡΠΈΠ±ΠΊΡ:
../node_modules/@types/bluebird/index.d.ts:750:72 - ΠΎΡΠΈΠ±ΠΊΠ° TS2583: Π½Π΅ ΡΠ΄Π°Π΅ΡΡΡ Π½Π°ΠΉΡΠΈ ΠΈΠΌΡ Β«ΠΠ°ΡΡΠ°Β». ΠΠ°ΠΌ Π½ΡΠΆΠ½ΠΎ ΠΈΠ·ΠΌΠ΅Π½ΠΈΡΡ ΡΠ΅Π»Π΅Π²ΡΡ Π±ΠΈΠ±Π»ΠΈΠΎΡΠ΅ΠΊΡ? ΠΠΎΠΏΡΠΎΠ±ΡΠΉΡΠ΅ ΠΈΠ·ΠΌΠ΅Π½ΠΈΡΡ ΠΏΠ°ΡΠ°ΠΌΠ΅ΡΡ ΠΊΠΎΠΌΠΏΠΈΠ»ΡΡΠΎΡΠ° lib
Π½Π° es2015 ΠΈΠ»ΠΈ Π½ΠΎΠ²Π΅Π΅.
750 ΡΡΠ°ΡΠΈΡΠ΅ΡΠΊΠΈΡ
ΠΎΠΏΠΎΡ
Π― ΡΠ°ΠΊΠΆΠ΅ ΠΏΠΎΠ»ΡΡΠ°Ρ Π΅ΡΠ΅ ΠΎΠ΄Π½Ρ ΠΎΡΠΈΠ±ΠΊΡ Π² ΡΠ΅Π΄Π°ΠΊΡΠΎΡΠ΅ ΠΊΠΎΠ΄Π°:
Π€Π°ΠΉΠ» /Users/harry.gothold/Documents/api-call-weather/src/app.ts Π½Π΅ ΡΠ²Π»ΡΠ΅ΡΡΡ ΠΌΠΎΠ΄ΡΠ»Π΅ΠΌ.
ΠΡΠΎ ΡΠ΅ΡΡ, ΠΊΠΎΡΠΎΡΡΠΉ Ρ ΠΏΡΡΠ°ΡΡΡ Π·Π°ΠΏΡΡΡΠΈΡΡ:
`
ΠΈΠΌΠΏΠΎΡΡΠΈΡΠΎΠ²Π°ΡΡ * ΠΊΠ°ΠΊ ΠΏΡΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠ΅ ΠΈΠ· '../src/app';
// ΠΈΠΌΠΏΠΎΡΡΠΈΡΠΎΠ²Π°ΡΡ * ΠΊΠ°ΠΊ ΡΠ°ΠΉ ΠΈΠ· 'chai';
// ΠΈΠΌΠΏΠΎΡΡΠΈΡΠΎΠ²Π°ΡΡ {ΡΠ΅Π·ΡΠ»ΡΡΠ°Ρ} ΠΈΠ· '../app';
var chai = require ('chai');
var sinon = require ('sinon');
const ΠΎΠΆΠΈΠ΄Π°ΡΡ = chai.expect;
ΠΎΠΏΠΈΡΠ°ΡΡ ('ΡΠ΅Π·ΡΠ»ΡΡΠ°Ρ', ΡΡΠ½ΠΊΡΠΈΡ () {
it ('ΡΠ»Π΅Π΄ΡΠ΅Ρ Π²ΡΠ·ΡΠ²Π°ΡΡ Ρ ΠΏΠΎΠΌΠΎΡΡΡ ΠΎΠΏΠΈΡΠ°Π½ΠΈΡ ΠΏΠΎΠ³ΠΎΠ΄Ρ', (Π³ΠΎΡΠΎΠ²ΠΎ) => {
ΠΎΠΆΠΈΠ΄Π°ΡΡ (ΡΠ΅Π·ΡΠ»ΡΡΠ°Ρ) .to.eventually.equal ('ΡΠΈΡΡΠΎΠ΅ Π½Π΅Π±ΠΎ');
ΠΡΠΏΠΎΠ»Π½Π΅Π½ΠΎ();
});
}); `
ΠΡΠΎ ΠΈΡΡ
ΠΎΠ΄Π½ΡΠΉ ΠΊΠΎΠ΄ ts:
`let request = require ('request');
let Promise = require ('bluebird');
function getData () {
Π²Π΅ΡΠ½ΡΡΡ Π½ΠΎΠ²ΠΎΠ΅ ΠΎΠ±Π΅ΡΠ°Π½ΠΈΠ΅ ((ΡΠ΅ΡΠΈΡΡ: Π»ΡΠ±ΠΎΠ΅, ΠΎΡΠΊΠ»ΠΎΠ½ΠΈΡΡ: Π»ΡΠ±ΠΎΠ΅) => {
Π·Π°ΠΏΡΠΎΡ ('https://api.openweathermap.org/data/2.5/forecast?id=2643743&APPID=99eaec08987344591490f9a6ee213155', {json: true},
(err: any, res: any, body: any) => {
ΡΠ°Π·ΡΠ΅ΡΠΈΡΡ (body.list [0] .weather [0] .description);
reject (err, 'Π ΡΠΎΠΆΠ°Π»Π΅Π½ΠΈΡ, ΠΏΡΠΈ Π·Π°Π³ΡΡΠ·ΠΊΠ΅ Π΄Π°Π½Π½ΡΡ
ΠΏΡΠΎΠΈΠ·ΠΎΡΠ»Π° ΠΎΡΠΈΠ±ΠΊΠ°');
});
});
};
ΡΡΠ½ΠΊΡΠΈΡ result (weatherDescription: any) {
console.log ( The weather today is ${weatherDescription}
);
}
ΠΏΠΎΠ»ΡΡΠΈΡΡ Π΄Π°Π½Π½ΡΠ΅()
.then ((weatherDescription: any) => {
ΡΠ΅Π·ΡΠ»ΡΡΠ°Ρ (weatherDescription)
})
.catch ((err: any) => {
Π±ΡΠΎΡΠΈΡΡ (ΠΎΡΠΈΠ±ΠΊΠ°)
});
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, / Π Π°Π·ΡΠ΅ΡΠΈΡΡ ΠΊΠΎΠΌΠΏΠΈΠ»ΡΡΠΈΡ ΡΠ°ΠΉΠ»ΠΎΠ² javascript. /// "checkJs": true, / Π‘ΠΎΠΎΠ±ΡΠ°ΡΡ ΠΎΠ± ΠΎΡΠΈΠ±ΠΊΠ°Ρ
Π² ΡΠ°ΠΉΠ»Π°Ρ
.js. /// "jsx": "preserve", / Π£ΠΊΠ°ΠΆΠΈΡΠ΅ Π³Π΅Π½Π΅ΡΠ°ΡΠΈΡ ΠΊΠΎΠ΄Π° JSX: 'preserve', 'react-native' ΠΈΠ»ΠΈ 'react'. /// "ΠΎΠ±ΡΡΠ²Π»Π΅Π½ΠΈΠ΅": true, / Π‘ΠΎΠ·Π΄Π°Π΅Ρ ΡΠΎΠΎΡΠ²Π΅ΡΡΡΠ²ΡΡΡΠΈΠΉ ΡΠ°ΠΉΠ» '.d.ts'. /// "DeclarationMap": true, / Π‘ΠΎΠ·Π΄Π°Π΅Ρ ΠΈΡΡ
ΠΎΠ΄Π½ΡΡ ΠΊΠ°ΡΡΡ Π΄Π»Ρ ΠΊΠ°ΠΆΠ΄ΠΎΠ³ΠΎ ΡΠΎΠΎΡΠ²Π΅ΡΡΡΠ²ΡΡΡΠ΅Π³ΠΎ ΡΠ°ΠΉΠ»Π° '.d.ts'. /// "sourceMap": true, / Π‘ΠΎΠ·Π΄Π°Π΅Ρ ΡΠΎΠΎΡΠ²Π΅ΡΡΡΠ²ΡΡΡΠΈΠΉ ΡΠ°ΠΉΠ» '.map'. /// "outFile": "./", / ΠΠ±ΡΠ΅Π΄ΠΈΠ½ΠΈΡΡ ΠΈ ΠΏΠ΅ΡΠ΅Π΄Π°ΡΡ Π²ΡΠ²ΠΎΠ΄ Π² ΠΎΠ΄ΠΈΠ½ ΡΠ°ΠΉΠ». /// "outDir": "./", / ΠΠ΅ΡΠ΅Π½Π°ΠΏΡΠ°Π²ΠΈΡΡ ΡΡΡΡΠΊΡΡΡΡ Π²ΡΠ²ΠΎΠ΄Π° Π² ΠΊΠ°ΡΠ°Π»ΠΎΠ³. /// "rootDir": "./", / Π£ΠΊΠ°ΠΆΠΈΡΠ΅ ΠΊΠΎΡΠ½Π΅Π²ΠΎΠΉ ΠΊΠ°ΡΠ°Π»ΠΎΠ³ Π²Ρ
ΠΎΠ΄Π½ΡΡ
ΡΠ°ΠΉΠ»ΠΎΠ². ΠΡΠΏΠΎΠ»ΡΠ·ΡΠΉΡΠ΅ Π΄Π»Ρ ΡΠΏΡΠ°Π²Π»Π΅Π½ΠΈΡ ΡΡΡΡΠΊΡΡΡΠΎΠΉ Π²ΡΡ
ΠΎΠ΄Π½ΠΎΠ³ΠΎ ΠΊΠ°ΡΠ°Π»ΠΎΠ³Π° Ρ ΠΏΠΎΠΌΠΎΡΡΡ --outDir. /// "ΠΊΠΎΠΌΠΏΠΎΠ·ΠΈΡΠ½ΡΠΉ": true, / ΠΠΊΠ»ΡΡΠΈΡΡ ΠΊΠΎΠΌΠΏΠΈΠ»ΡΡΠΈΡ ΠΏΡΠΎΠ΅ΠΊΡΠ° /// "removeComments": true, / ΠΠ΅ Π²ΡΠ²ΠΎΠ΄ΠΈΡΡ ΠΊΠΎΠΌΠΌΠ΅Π½ΡΠ°ΡΠΈΠΈ Π΄Π»Ρ Π²ΡΠ²ΠΎΠ΄Π°. /// "noEmit": true, / ΠΠ΅ /// "importHelpers": true, / ΠΠΌΠΏΠΎΡΡΠΈΡΠΎΠ²Π°ΡΡ ΡΠΌΠΈΡΠ΅Π½ΡΡ Ρ
Π΅Π»ΠΏΠ΅ΡΠΎΠ² ΠΈΠ· 'tslib'. /// "downlevelIteration": true, / ΠΠ±Π΅ΡΠΏΠ΅ΡΠΈΠ²Π°Π΅ΠΌ ΠΏΠΎΠ»Π½ΡΡ ΠΏΠΎΠ΄Π΄Π΅ΡΠΆΠΊΡ ΠΈΡΠ΅ΡΠ°ΡΠΈΠΉ Π² 'for-of', spread ΠΈ Π΄Π΅ΡΡΡΡΠΊΡΡΡΠΈΡΠΎΠ²Π°Π½ΠΈΠΈ ΠΏΡΠΈ Π½Π°ΡΠ΅Π»ΠΈΠ²Π°Π½ΠΈΠΈ Π½Π° 'ES5' ΠΈΠ»ΠΈ 'ES3'. /// "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.