سلوك متوقع:
أتوقع أن يتم تجميع الكود الخاص بي بدون أخطاء
وتوقع أن يعمل بيان الاستيراد
السلوك الفعلي:
عندما أقوم بتشغيل 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 من "chai" ؛
// استيراد {نتيجة} من '../app' ؛
var chai = يتطلب ('chai') ؛
var sinon = يتطلب ('sinon') ؛
توقع const = chai.expect ؛
وصف ("النتيجة" ، الوظيفة () {
it ("يجب استدعاؤها مع weatherDescription" ، (تم) => {
توقع (نتيجة). to.to.eventually.equal ("سماء صافية") ؛
منجز()؛
}) ؛
}) ؛ `
هذا هو كود ts الأصلي:
"دع الطلب = يتطلب ('طلب') ؛
دع الوعد = يتطلب ('بلوبيرد') ؛
وظيفة getData () {
إرجاع وعد جديد ((حل: أي ، رفض: أي) => {
طلب ('https://api.openweathermap.org/data/2.5/forecast؟id=2643743&APPID=99eaec08987344591490f9a6ee213155' ، {json: true} ،
(يخطئ: أي ، الدقة: أي ، الجسم: أي) => {
حل (body.list [0] .weather [0] .description) ؛
رفض (يخطئ ، "عذرًا ، حدث خطأ أثناء جلب البيانات") ؛
}) ؛
}) ؛
} ؛
نتيجة الوظيفة (وصف الطقس: أي) {
console.log ( The weather today is ${weatherDescription}
) ؛
}
احصل على البيانات()
ثم ((weatherDescription: أي) => {
النتيجة (وصف الطقس)
})
.catch ((يخطئ: أي) => {
رمي (يخطئ)
}) ؛
module.exports = {
getData: function () {} ،
النتيجة: الوظيفة () {}
} `
وهذا ملف tsconfig الخاص بي:
"{
"compilerOptions": {
/ * الخيارات الأساسية /"الهدف": "es6" ، / تحديد الإصدار الهدف من ECMAScript: 'ES3' (افتراضي) ، 'ES5' ، 'ES2015' ، 'ES2016' ، 'ES2017' ، 'ES2018' أو 'ESNEXT'. /"module": "commonjs" ، / تحديد إنشاء رمز الوحدة النمطية: 'none' أو 'commonjs' أو 'amd' أو 'system' أو 'umd' أو 'es2015' أو 'ESNext'. /"lib": ["es5"، "es6"، "dom"]، / تحديد ملفات المكتبة التي سيتم تضمينها في التجميع. /// "allowJs": صحيح / السماح بتجميع ملفات جافا سكريبت. /// "checkJs": صحيح ، / الإبلاغ عن أخطاء في ملفات .js. /// "jsx": "تحفظ" ، / حدد إنشاء كود /// "تصريح": صحيح ، / يولد ملف '.d.ts مطابق. /// " signatureMap /// "sourceMap": صحيح ، / ينشئ ملف ".map" مطابق. /// "outFile": "./"، / Concatenate وإخراج الإخراج إلى ملف واحد. /// "outDir": "./" ، / إعادة توجيه بنية الإخراج إلى الدليل. /// "rootDir": "./" ، / حدد الدليل الجذر لملفات الإدخال. تُستخدم للتحكم في بنية دليل الإخراج باستخدام --outDir. /// "مركب": صحيح ، / تمكين تجميع المشروع /// "removeComments": صحيح ، / لا /// "noEmit": صحيح ، / لا تصدر مخرجات. /// "importHelpers": صحيح ، / استيراد أدوات المساعدة من "tslib". /// "downlevelIteration": صحيح ، / توفير الدعم الكامل للمواد التكرارية في "for-of" ، والانتشار ، والتدمير عند استهداف "ES5" أو "ES3". /// "عزل الوحدات
/* 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.