I'm trying to use a Promise
in my TypeScript application. But it doesn't seem like it's possible?
First I tried to do use Promise.all()
, but then I of course get "'Promise' only refers to a type, but is being used as a value here". And it doesn't make a difference if I instead try to instantiate the Promise by doing new Promise().all()
(or doing that in two steps, i.e first instantiating and then calling the method). And it also gives the same error message in my function headers where I do async getData(): Promise<X>
, which doesn't make any sense to me.
As suggested in some other threads about this issue I changed the target to "es6" from "es5" in my tsconfig.json. I also tried changing it to "es2005". This allowed me to build the application. But when I try to run it I get
Failed to instantiate module [module name] due to: Error: [$injector:nomod] Module '[module name]' is not available
Is there perhaps something else I also need to adjust when changing from es5 to es6?
I also tried adding "lib": [ "es2015" ]
to the compilerOptions in tsconfig.json as sugggested in another thread. But then I get a few hundred errors saying stuff like: Build: Cannot find name 'Element'. File: angular.d.ts
Edit: As suggested in the comments I also added "dom" to the lib array, which got rid of the compilation errors. But then instead get "ReferenceError: 'Promise' is undefined".
How do I solve this? I'm fine with any solution that lets me use Promise
.
Thanks in advance!