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

Defer generic awaited type #35064

Closed
wants to merge 4 commits into from
Closed

Defer generic awaited type #35064

wants to merge 4 commits into from

Conversation

jablko
Copy link
Contributor

@jablko jablko commented Nov 12, 2019

Roll up #33062, #33074, #33103, #33105, #33707 and #35284

Fixes #27711
Fixes #22469
Fixes #28427
Fixes #30390
Fixes #31722
Fixes #33559
Fixes #33562
Fixes #33752
Fixes #34924
Fixes #34937
Fixes #35136
Fixes #35258

@typescript-bot test this
@typescript-bot run dt
@typescript-bot user test this

@jablko jablko force-pushed the patch-22 branch 3 times, most recently from 4855cc2 to f8e58ec Compare November 18, 2019 14:18
@orta
Copy link
Contributor

orta commented Nov 18, 2019

@typescript-bot test this
@typescript-bot user test this
@typescript-bot run dt

@typescript-bot
Copy link
Collaborator

typescript-bot commented Nov 18, 2019

Heya @orta, I've started to run the parallelized community code test suite on this PR at f8e58ec. You can monitor the build here. It should now contribute to this PR's status checks.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Nov 18, 2019

Heya @orta, I've started to run the extended test suite on this PR at f8e58ec. You can monitor the build here. It should now contribute to this PR's status checks.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Nov 18, 2019

Heya @orta, I've started to run the parallelized Definitely Typed test suite on this PR at f8e58ec. You can monitor the build here. It should now contribute to this PR's status checks.

@typescript-bot
Copy link
Collaborator

The user suite test run you requested has finished and failed. I've opened a PR with the baseline diff from master.

@orta
Copy link
Contributor

orta commented Jan 22, 2020

@typescript-bot test this
@typescript-bot user test this
@typescript-bot run dt

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jan 22, 2020

Heya @orta, I've started to run the extended test suite on this PR at 3c20282. You can monitor the build here. It should now contribute to this PR's status checks.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jan 22, 2020

Heya @orta, I've started to run the parallelized Definitely Typed test suite on this PR at 3c20282. You can monitor the build here. It should now contribute to this PR's status checks.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jan 22, 2020

Heya @orta, I've started to run the parallelized community code test suite on this PR at 3c20282. You can monitor the build here. It should now contribute to this PR's status checks.

@typescript-bot
Copy link
Collaborator

The user suite test run you requested has finished and failed. I've opened a PR with the baseline diff from master.

@orta
Copy link
Contributor

orta commented Jan 23, 2020

Looks like most of that diff is just file number changing

There is a few errors though at this location - which I think could be correct. Does that feel right?

@orta
Copy link
Contributor

orta commented Jan 23, 2020

Relates to #35998

Copy link
Contributor

@ExE-Boss ExE-Boss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The then method only needs to be assignable to Function.

src/lib/es5.d.ts Outdated
// The undefined case is for strictNullChecks false, in which case
// undefined extends PromiseLike<infer U> is true, which would otherwise
// make Awaited<undefined> -> unknown.
type Awaited<T> = T extends undefined ? T : T extends PromiseLike<infer U> ? U : T extends { then(...args: any[]): any } ? unknown : T;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
type Awaited<T> = T extends undefined ? T : T extends PromiseLike<infer U> ? U : T extends { then(...args: any[]): any } ? unknown : T;
type Awaited<T> = T extends undefined ? T : T extends PromiseLike<infer U> ? U : T extends { then: Function } ? unknown : T;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Works, thanks for your help! Done. ✔️

@jablko jablko force-pushed the patch-22 branch 2 times, most recently from 3e6abf1 to b48a356 Compare January 25, 2020 20:23
Copy link
Member

@rbuckton rbuckton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not believe this is the correct solution to this problem.

}

const promisedType = getPromisedTypeOfPromise(type);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't agree with this change. This completely removes support for recursively unwrapping a non-native promise, which is a core capability of await and our type-system support for it which has existed since the feature was added.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can a non-native promise resolve to another promise? If not, then await isn't recursive and I think this change is safe?

If it can, then I concede that implies a recursive awaited solution.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, non‑native promises can resolve to an object with a .then function property, which await will resolve recursively.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't that violate Promises/A+?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jablko: non-native promise-like implementations aren't all guaranteed to be Promise/A+. In the past, JQuery's defer created something promise-like (i.e. it has a callable then that accepted fulfill/reject callbacks), but it did not recursively unwrap. This is why native await and native Promise both recursively unwrap (to defend against non-Promise/A+-compliant promise-likes)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

await is recursive for non-native promises. In https://tc39.es/ecma262/#await, the value is passed to PromiseResolve which adopts the foreign promise and performs recursive unwrapping.

Copy link
Contributor Author

@jablko jablko Feb 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I concede that await is recursive for non-compliant promises. Does supporting non-compliant promises justify introducing a new kind of type?

There's only ever been incomplete support for non-compliant promises in TypeScript. TypeScript's native promise type hasn't recursively unwrapped non-compliant promises until now. For native and A+-compliant promises, await isn't recursive because they can't be nested.

Is a non-compliant promise more likely actually an error? Supporting non-compliant promises can be error prone, masking what are otherwise errors.

@sandersn sandersn added this to Gallery in Pall Mall Jan 28, 2020
@sandersn sandersn moved this from Gallery to Nostrum in Pall Mall Jan 28, 2020
@jablko jablko force-pushed the patch-22 branch 2 times, most recently from d3f708d to 0602062 Compare January 29, 2020 17:28
@sandersn sandersn moved this from Nostrum to Limbo in Pall Mall Jan 30, 2020
@jablko jablko force-pushed the patch-22 branch 2 times, most recently from 7da42e8 to 034a6fc Compare February 3, 2020 15:29
@sandersn sandersn added this to Needs review in PR Backlog Feb 3, 2020
Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like there are outstanding comments on this PR, so I'm going to request changes to help me track our PR backlog.

PR Backlog automation moved this from Needs review to Waiting on author Feb 3, 2020
@sandersn sandersn removed this from Limbo in Pall Mall Feb 3, 2020
@jablko jablko force-pushed the patch-22 branch 4 times, most recently from 340aaa9 to d802893 Compare February 10, 2020 20:01
@jablko jablko force-pushed the patch-22 branch 4 times, most recently from 5cb7c3f to 49ad9c9 Compare February 13, 2020 15:42
You can include es2015.promise.d.ts without es2015.iterable.d.ts. It was
moved to es2015.promise.d.ts in microsoft#31117
@sandersn
Copy link
Member

This PR hasn't seen any activity for quite a while, so I'm going to close it to keep the number of open PRs manageable. Feel free to open a fresh PR or continue the discussion here.

@sandersn sandersn closed this Feb 27, 2020
PR Backlog automation moved this from Waiting on author to Done Feb 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment