-
Notifications
You must be signed in to change notification settings - Fork 12k
Is there a way to use async/await with angular-cli? #4554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think you will have to wait for Angular 4 to be able to use TS >= 2.1 Check #3525 |
the newest version of the cli (beta-31) should have support for generating a project with angular 4 which mean you can safely use type 2.1 |
Closing as answered. |
Actually not answered at all((( I already use TS 2.1.5. How switching to Angular 4 could change things with UglifyJS? |
I played about this; actually Typescript 2.1.0 works with es5. I tested grabbing cli beta-31 and applied -ng4 to get 4.0.0-beta.7 So async/await work without having to change target to es6. |
I tested it with non-beta @angular 2 stack as well: Manually updating my Typescript to 2.1.0 allows me to use async/await on code even on es5, and it does build with -prod flag then (whereas es6 doesn't). My project was small - the Hero Manager tutorial, so it might miss some obvious, but I could repro the issue present here and I could solve the working version of async/await in that project. |
@kallex Could you please share your tsconfig for ng2+es5+async/awat + prod flag? Because when I change target to 'es5' async/await become broken |
@alexbyk here's full repo. https://github.com/kallex/herotutorial There were some probably unnecessary experiments. The final step that succeeded for me was uninstalling Typescript and reinstalling it as 2.1.0 (modified just package.json ran npm install). Edit: For me it was also broken with 2.0.3 Typescript version; in my case the WebStorm editor was first to complain about async/await if I had es5 enabled. After updating Typescript, WebStorm was happy and so was the build chain still with es5. |
@kallex thanks a lot. I'll check it out tomorrow |
@kallex thanks again. Indeed I reinstalled all packages and that helped |
@alexbyk Thank you for pointing this topic out. I was interested in it as well, but it wasn't that much brought up elsewhere. And then I was just about in proper situation to start from scratch and explore :-) I wanted to find a solution that stays mainly on angular-git; with as little modifications as possible - and I'm glad we did :-) |
@kallex Thanks.I had solved to set package.typescript as 2.1 :-) |
I am also having issues with trying to get await to work, and can't figure it out. typescript 2.2.2 tsconfig:
"@angular/cli": "^1.0.0", Within a class I am trying to write this let foo = await this.http.get('/api/bar'); but am getting the compile error
what am I missing ? thanks! |
Just FYI, the function you are using await in must be tagged with async The error message is not very helpful at suggesting this.
|
The following worked for me:
My problem is that async/await randomly fails to wait for Angular to resolve a click, or a change of URL. If I run each test independently, then everything is fine and quick. I used to use browser.sleep one year ago with Angular1.x, I'm glad we can use await/async, that's clearly the future ! |
@Thommas Maybe not relevant, but Angular 4.1.3 made a change to Promises used by the Router
So maybe awaiting a Router's Promise was broken previous to 4.1.3? |
Just updated to 4.1.3, same behavior. I've tried using browser.sleep to fix some tests, but I still end up with 2/3 random tests failed out of 35 tests. When I run tests one by one, they all pass without any problem. A typical test looks like this: e2e-spec.ts
app.po.ts
EDIT: Should have asked this question to my rubber duck. Because I found the obvious flaw in this code. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
I'm trying to use new cool async/await feature (I've updated all packages using ncu -a before, tsc version is 2.1.5), but there are some problems
With "target": "es6" and production mode:
With "target": "es5",
As I understand, this is because UglifyJS doesn't support es6.
Without
--prod
and with es6 target it works. With--prod
doesn'tIs there any way to use angular-cli + async/await without problem?
The text was updated successfully, but these errors were encountered: