Typescript: 遇到2编译错误

创建于 2018-10-25  ·  1评论  ·  资料来源: microsoft/TypeScript

预期的行为:
我期望我的代码可以编译而不会出现错误
并期待导入声明起作用

实际行为:
当我运行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 = require('chai');
var sinon = require('sinon');
const Expect = chai.expect;

describe('result',function(){
它(“应该用weatherDescription调用”,(完成)=> {
期望(结果)最终等于('晴朗的天空');
完毕();
});
});`

这是原始的ts代码:
让请求= require('request');
让诺言= require('bluebird');

函数getData(){
返回新的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,'对不起,获取数据时出错');
});
});
};

函数结果(天气描述:任意){
console.log( The weather today is ${weatherDescription} );
}

getData()
.then((weatherDescription:any)=> {
结果(天气描述)
})
.catch((err:any)=> {
抛出(错误)
});

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

这是我的tsconfig文件:
`{
“ compilerOptions”:{
/ *基本选项/“目标”:“ es6”,/指定ECMAScript目标版本:“ ES3”(默认),“ ES5”,“ ES2015”,“ ES2016”,“ ES2017”,“ ES2018”或“ ESNEXT”。 /“模块”:“ commonjs”,/指定模块代码生成:“无”,“ commonjs”,“ amd”,“系统”,“ umd”,“ es2015”或“ ESNext”。 /“ lib”:[“ es5”,“ es6”,“ dom”],/指定要包含在编译中的库文件。 ///“ allowJs”:true,/ /允许编译javascript文件。 ///“ 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 等级

相关问题

jbondc picture jbondc  ·  3评论

Antony-Jones picture Antony-Jones  ·  3评论

DanielRosenwasser picture DanielRosenwasser  ·  3评论

manekinekko picture manekinekko  ·  3评论

Zlatkovsky picture Zlatkovsky  ·  3评论