Typescript cannot find name 'Promise' despite using ECMAScript 6

本秂侑毒 提交于 2019-12-14 01:18:30

问题


I am currently trying to develop a node.js application in Visual Studio 2015 and it keeps telling me

TS2304 Cannot find the name 'Promise'

In the project settings I have ECMAScript 6 configured as build system and ES 2015 as module system.

I already tried

  • how to use es6-promises with typescript?

  • How to use Typescript with native ES6 Promises

without success, but in the second link they say that it should work with ECMAScript version set to 6, but it changes nothing for me.

EDIT: I now did some more diagnosing. The problem seems to be that there is a mismatch between the ECMAScript Versions used by IntelliSense and the build system.

I discovered this by using more ECMAScript 6 functions, which resulted in the following IntelliSense complaint:

TS1311 Async functions are only available when targeting ECMAScript 6 and higher.

So the new question: Where do I set the ECMAScript version that IntelliSense uses?


回答1:


This seems to be an oversight (I had the same issue). You can easily make the problem go away if you install the type definition .d.ts files.

If you are using Nuget, just install from the Package Manager console with:

PM> Install-Package es6-promise.TypeScript.DefinitelyTyped


来源:https://stackoverflow.com/questions/35972037/typescript-cannot-find-name-promise-despite-using-ecmascript-6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!