Skip to content
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

Promise<T> should be Promise<T1,T2> #22162

Closed
ORESoftware opened this issue Feb 24, 2018 · 4 comments
Closed

Promise<T> should be Promise<T1,T2> #22162

ORESoftware opened this issue Feb 24, 2018 · 4 comments
Labels
Duplicate An existing issue was already created

Comments

@ORESoftware
Copy link

ORESoftware commented Feb 24, 2018

Sorry if this is a dupe issue, but I am having trouble determining how to solve some typing issues surrounding promises.

If we have a method:

 foo(bar) : Promise<boolean | string> {
   if(bar){
      return Promise.resolve(true);   // boolean type
    }
    return Promise.reject('a string');  // string type
 }

I am really really confused, why the typings for Promises don't take two parameters, should it not be:

 foo(bar) : Promise<boolean, string> {    // use , instead of |
   if(bar){
      return Promise.resolve(true);   
    }
    return Promise.reject('a string');
 }

Currently, I am trying to solve this SO issue, and yet again the problem of specifying the different resolution types is coming up. I guess I just want to know why it is this way.

https://stackoverflow.com/questions/48954365/use-generics-to-specify-type-of-return-value/48958224

@jack-williams
Copy link
Collaborator

Do you intend the second type (call it E) to be the input type to the catch or onrejected continuations? The input to these functions can also come from a throw, not just Promise.reject, and as TypeScript doesn't do effect typing it wont track this.

I think rather than making promises (pun intended) the checker can't keep, they just treat the error type as any.

@DanielRosenwasser
Copy link
Member

Looks like a duplicate of #5413 (#3834 is also possibly related?)

@ORESoftware
Copy link
Author

ORESoftware commented Feb 24, 2018

@jack-williams yeah Promise<boolean,string> means the resolved type is always a boolean, and the rejected type is always a string, nothing too crazy... lol...is it too much to ask? idk

at the moment, mixing resolved type with rejected type is making me a little crazy upstairs

@mhegazy mhegazy added the Duplicate An existing issue was already created label Feb 27, 2018
@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

5 participants