-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
1.8 breaks use of third-party promise libraries #6737
Comments
pinging @rbuckton |
As an aside, it would be awesome if I didn't have to shim this at all, but rather the compiler could handle |
As of TypeScript 1.8 we are restricting the allowable set of return type's for an async function to only the global Unfortunately, this means that you would need to do one of three things:
An example of [3] might be: declare global {
interface Promise<T> extends PromiseLike<T> {}
}
function __awaiter(thisArg: any, _arguments: any, P: any, generator: Function) {
return new (P || (P = angular.injector(['ng']).get("$q")))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments)).next());
});
}
async function foo() {
} |
Is there a way to make the ES6 included-by-default |
relevant: #4692 (comment) |
Yuck. 👎 |
What's the logic behind the change away from allowing any |
@bytenik I think it's a good thing that TS follows ES semantics for async functions, but what's still missing is a straightforward way to polyfill |
Based on that logic, I agree. Unfortunately until there's a better way to stick my own promise in, I'm stuck with 1.7. Does the awaiter suggestion above work if I use the built-in es6 library and don't replace the global Promise? Or will I conflict? |
Keep in mind that the Changing |
@rbuckton Absolutely, but its a stop-gap that I can use now. es6-shim won't help here; I have es6 compilation already, and I need to use $q rather than es6 promises. |
@bytenik not sure if you saw my last comment above as we both posted about the same time - it's another approach you could take. |
this is all rubish. native promise are said to be not faster. and many libraries tend to use bluebird promise. I'm using sequelize with async await and this break sequelize as I would be getting unhandled execeptions even when I wrap it in a try catch block. please sometimes it's better flex your decision of going with the spec than to cause large breakage in apps that use async await. only a few libraries you the native promises and many promise implementations mostly align with the spec. so the bring your own promise should an option that should be kept. async await jobs is to provide a clean way to write async code. not try to be wrapping it in another callback |
fixed by #6967 |
I'm currently developing in TS 1.7, compiling to ES6, and transpiling with Babel to ES5. I use Angular 1.x for my frontend development currently.
I am able to leverage async functions by returning a custom type,
QPromise
, for which I've written a definition like this:I then create a JavaScript file with a definition QPromise:
While less than elegant, this has been an acceptable shim for now so that I can use async while still using Angular's $q library, which is needed to get Angular digest to occur automatically.
TS 1.8 no longer lets me return a
QPromise<T>
, complaining:error TS1064: The return type of an async function or method must be the global Promise<T> type.
This all but breaks my ability to work with Angular 1 and still use TS async functions.
The text was updated successfully, but these errors were encountered: