-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Unable to use custom Promise definition with two generic parameters as return value for async function #12973
Comments
I would not recommend changing the global Promise type. the compiler makes assumptions about how it is defined. same goes for PromiseLike. if you want to use a different Promise definition, and you are running under async function foo (a) : MyPromise<string, number, undefined> {
.....
} |
The suggestion is to relax this assumption. There is no actual change to the runtime behaviour of Promise; the only change is that the errors are strongly typed. I don't really see why the compiler should enforce this restriction. Also, in |
This is a matter of checked vs. unchecked exceptions. You can get around this by subclassing It's there for the same reason exceptions in regular non-promise functions aren't declared. It would make no sense to enforce this for async functions but not regular ones: public async foo() : number throws TypeError { // <- we don't do that in TS
return 10;
} Checked exceptions have traditionally been very unpopular in languages that sport them (Java). |
how? |
I don't think so. |
@gcnew I'd like to retract that statement. Mainly because I don't have anything objective to back it up and I don't think it's the debate we should be having anyway. @NoelAbrahams |
That was something I thought would work, but the way Promise is defined in The original issue was not really about errors: it was to relax the restrictions on how |
#12737 is fixed it says |
related: #10751 |
TypeScript Version: 2.1.4
Code
tsconfig.json
Minimal Custom lib.d.ts
Sample Code
Expected behavior:
No compilation errors
Actual behavior:
The compiler prints the following errors:
I would like the rule
Global type 'Promise' must have 1 type parameter(s)
to be relaxed if possible.Thanks!
Related issues:
#7588
#5413
#12737
#12292
The text was updated successfully, but these errors were encountered: