Typescript: Mendapatkan 2 kesalahan kompilasi

Dibuat pada 25 Okt 2018  ·  1Komentar  ·  Sumber: microsoft/TypeScript

Perilaku yang diharapkan:
Saya mengharapkan kode saya untuk dikompilasi tanpa kesalahan
Dan mengharapkan pernyataan impor berfungsi

Perilaku sebenarnya:
Ketika saya menjalankan tsc app.ts, saya mendapatkan kesalahan ini:
../node_modules/@types/bluebird/index.d.ts:750:72 - kesalahan TS2583: Tidak dapat menemukan nama 'Peta'. Apakah Anda perlu mengubah perpustakaan target Anda? Coba ubah opsi compiler lib ke es2015 atau yang lebih baru.

750 alat peraga statis(peta: Dapat diselesaikan>>): Bluebird>;
Tautan Taman Bermain:

Saya juga mendapatkan kesalahan lain di editor kode saya:
File '/Users/harry.gothold/Documents/api-call-weather/src/app.ts' bukan modul.

Ini adalah tes yang saya coba jalankan:
`
impor * sebagai aplikasi dari '../src/app';
// impor * sebagai chai dari 'chai';
// impor {hasil} dari '../app';
var chai = membutuhkan ('chai');
var sinon = membutuhkan ('sinon');
const berharap = chai.expect;

mendeskripsikan ('hasil', fungsi () {
it ('harus dipanggil dengan weatherDescription', (done) => {
mengharapkan (hasil) .to.eventually.equal ('langit cerah');
selesai ();
});
}); `

Ini adalah kode ts asli:
`biarkan permintaan = membutuhkan ('permintaan');
biarkan janji = membutuhkan ('bluebird');

function getData () {
kembalikan janji baru ((selesaikan: apa pun, tolak: apa pun) => {
request ('https://api.openweathermap.org/data/2.5/forecast?id=2643743&APPID=99eaec08987344591490f9a6ee213155', {json: true},
(err: any, res: any, body: any) => {
menyelesaikan (body.list [0] .weather [0] .description);
tolak (err, 'Maaf, ada kesalahan saat mengambil data');
});
});
};

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

getData ()
.then ((weatherDescription: any) => {
hasil (deskripsi cuaca)
})
.catch ((err: any) => {
lempar (err)
});

module.exports = {
getData: function () {},
hasil: function () {}
} `

Dan ini file tsconfig saya:
`{
"compilerOptions": {
/ * Opsi Dasar /"target": "es6", / Tentukan versi target ECMAScript: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018' or 'ESNEXT'. /"module": "commonjs", / Tentukan pembuatan kode modul: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', atau 'ESNext'. /"lib": ["es5", "es6", "dom"], / Tentukan file perpustakaan yang akan disertakan dalam kompilasi. /// "allowJs": true, / Izinkan file javascript untuk dikompilasi. /// "checkJs": true, / Laporkan kesalahan dalam file .js. /// "jsx": "melestarikan", / Tentukan pembuatan kode JSX: 'melestarikan', 'react-native', atau 'react'. /// "declaration": true, / Menghasilkan file '.d.ts' yang sesuai. /// "declarationMap": true, / Menghasilkan peta sumber untuk setiap file '.d.ts' yang sesuai. /// "sourceMap": true, / Menghasilkan file '.map' yang sesuai. /// "outFile": "./", / Menggabungkan dan mengeluarkan keluaran ke file tunggal. /// "outDir": "./", / Alihkan struktur keluaran ke direktori. /// "rootDir": "./", / Tentukan direktori root dari file masukan. Gunakan untuk mengontrol struktur direktori keluaran dengan --outDir. /// "komposit": true, / Aktifkan kompilasi proyek /// "removeComments": true, / Jangan berikan komentar ke keluaran. /// "noEmit": true, / Jangan /// "importHelpers": true, / Impor /// "downlevelIteration": true, / Memberikan dukungan penuh untuk iterable di 'for-of', menyebar, dan merusak saat menargetkan 'ES5' atau 'ES3'. /// " isolasiModules

/* 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

>Semua komentar

Harap arahkan pertanyaan seperti ini ke Stack Overflow.

Apakah halaman ini membantu?
0 / 5 - 0 peringkat

Masalah terkait

bgrieder picture bgrieder  ·  3Komentar

MartynasZilinskas picture MartynasZilinskas  ·  3Komentar

Antony-Jones picture Antony-Jones  ·  3Komentar

fwanicka picture fwanicka  ·  3Komentar

uber5001 picture uber5001  ·  3Komentar