2

I'm using TypeScript But I have This Error:

[ts] Cannot find name 'async'

And This is my Code:

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

This is my 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"
  }
}

But I Can use Asynce Like Blow and haven't any error and I Don't Know Why I have Error In above Example

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

4
  • check your target platform in tsconfig.json or .csproject if it visual studio Commented May 3, 2017 at 6:32
  • Have you installed the typescript module globally? Commented May 3, 2017 at 7:02
  • yes, but still I have error Commented May 3, 2017 at 7:16
  • could you please share your TypeScript version or package.json Commented May 3, 2017 at 9:32

1 Answer 1

2

Solved With This:

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

}

And I Called With:

test();

And I haven't any Error

Sign up to request clarification or add additional context in comments.

3 Comments

weird, because then you are not using native TypeScript async functions.
I used That but , not work, In my case Solved with above code, thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.