gpt4 book ai didi

javascript - ts 无法通过 TypeScript 找到名称 'async'

转载 作者:太空宇宙 更新时间:2023-11-04 00:23:22 24 4
gpt4 key购买 nike

我正在使用 TypeScript 但出现此错误:

[ts] Cannot find name 'async'

这是我的代码:

async someAsyncCode() {
let asyncFn = () => {
return new Promise((resolve: Function) => { resolve(2); });
}
// should log `2`
console.log(await asyncFn());
}

这是我的 Packeges.json:

{
"name": "simple-typescript-gulp",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/aliparhamnia/simple-typescript-gulp.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/aliparhamnia/simple-typescript-gulp/issues"
},
"homepage": "https://github.com/aliparhamnia/simple-typescript-gulp#readme",
"dependencies": {
"@types/core-js": "^0.9.41",
"@types/es6-promise": "0.0.32",
"@types/node": "^7.0.13",
"async": "^2.4.0",
"bluebird": "^3.5.0",
"dotenv": "^4.0.0",
"json-query": "^2.2.2",
"nano": "^6.2.0",
"node-telegram-bot-api": "^0.27.0",
"q": "^1.5.0",
"sessionstorage": "0.0.2"
},
"devDependencies": {
"@types/node": "^7.0.12",
"babel-preset-es2015": "^6.24.1",
"gulp": "^3.9.1",
"gulp-typescript": "^3.1.6",
"ts-node": "^2.1.0",
"typescript": "^2.2.1",
"typings": "^2.1.1"
}
}

但是我可以使用 Asynce Like Blow 并且没有任何错误,而且我不知道为什么在上面的示例中出现错误

const x = async () => await getmessage();

最佳答案

解决了这个问题:

var test = async() => {
let asyncFn = () => {
return new Promise((resolve: Function) => { resolve(2); });
}
// should log `2`
console.log(await asyncFn());

}

我调用:

test();

我没有任何错误

关于javascript - ts 无法通过 TypeScript 找到名称 'async',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43752542/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com