Uh oh!
There was an error while loading. Please reload this page.
Remove optionality for Promise resolve callback - #39817
Conversation
Ron Buckton (rbuckton)
commented
Jul 29, 2020
TypeScript Bot (@typescript-bot) run dt |
Heya Ron Buckton (@rbuckton), I've started to run the extended test suite on this PR at b198eb6. You can monitor the build here. |
Heya Ron Buckton (@rbuckton), I've started to run the parallelized Definitely Typed test suite on this PR at b198eb6. You can monitor the build here. |
Heya Ron Buckton (@rbuckton), I've started to run the parallelized community code test suite on this PR at b198eb6. You can monitor the build here. |
TypeScript Bot (typescript-bot)
commented
Jul 29, 2020
The user suite test run you requested has finished and failed. I've opened a PR with the baseline diff from master. |
Ryan Cavanaugh (@RyanCavanaugh), Wesley Wigham (@weswigham), Daniel Rosenwasser (@DanielRosenwasser): This one is interesting because its an improvement for TypeScript code, but results in "breaks" for JavaScript code. In TS, the expectation is that Removing optionality for |
Wesley Wigham (weswigham)
commented
Jul 29, 2020
Hm.... I mean, |
Ron Buckton (rbuckton)
commented
Jul 30, 2020
Daniel Rosenwasser (@DanielRosenwasser), Ryan Cavanaugh (@RyanCavanaugh): I'm still interested in whether this is considered a "break" and if it should wait for 4.1, or if we should consider Wesley Wigham (@weswigham)'s suggestion to extend the |
This late in the release, I'd really prefer waiting until 4.1 for anything that feels close to a breaking change. |
ExE Boss (ExE-Boss)
commented
Jul 31, 2020
Does that mean that #29131 has been fixed? |
Andrew Branch (andrewbranch)
commented
Aug 7, 2020
After discussing it in the design meeting, the suggestion to make trailing |
Ron Buckton (rbuckton)
commented
Aug 20, 2020
TypeScript Bot (@typescript-bot) user test this |
Heya Ron Buckton (@rbuckton), I've started to run the parallelized community code test suite on this PR at ff5009c. You can monitor the build here. |
From the user tests: office-ui-fabricThis is due to the fact that the promise created here has no type argument and is inferred to xterm.jsThis is again due to an untyped adonis-frameworkThis is due to the fact this is a .js file and our user tests compile js files with chrome-devtools-frontendIn these cases, the promises need an appropriate contextual type. Some are typed as npmThis is again due to the fact we compile our JS user tests using puppeteer
Daniel Rosenwasser (@DanielRosenwasser), Ryan Cavanaugh (@RyanCavanaugh): Regarding our existing support for treating trailing I'm also considering the possibility of giving an asyncfunctionfoo(){// type is `Promise<unknown>`.constx=newPromise(()=>{});// type is `Promise<void>`awaitnewPromise(()=>{});}The result would be that some of the above errors would get the correct contextual type when the result is unused. I can create a separate PR for this case, which we can possibly discuss at the next design meeting. |
Ron Buckton (rbuckton)
commented
Aug 24, 2020
I've filed #40227 for the assignability related issue. |
Heya Ron Buckton (@rbuckton), I've started to run the parallelized Definitely Typed test suite on this PR at 47b29cc. You can monitor the build here. |
Ron Buckton (rbuckton)
commented
Sep 3, 2020
Heya Ron Buckton (@rbuckton), I've started to run the parallelized Definitely Typed test suite on this PR at 47b29cc. You can monitor the build here. |
Ron Buckton (rbuckton)
commented
Sep 3, 2020
Heya Ron Buckton (@rbuckton), I've started to run the parallelized Definitely Typed test suite on this PR at 47b29cc. You can monitor the build here. |
Ron Buckton (rbuckton)
commented
Sep 3, 2020
trying again... |
Heya Ron Buckton (@rbuckton), I've started to run the parallelized Definitely Typed test suite on this PR at 47b29cc. You can monitor the build here. |
Ron Buckton (rbuckton)
commented
Sep 3, 2020
One last time, now that hopefully dtslint-runner is fixed... |
Heya Ron Buckton (@rbuckton), I've started to run the parallelized Definitely Typed test suite on this PR at 47b29cc. You can monitor the build here. |
John Firebaugh (jfirebaugh)
commented
Sep 8, 2020
FYI, this is a breaking change for utility functions that externalize the exportfunctionpromiseResolveReject<T=void>(): [Promise<T>,(value?: T|PromiseLike<T>)=>void,(reason?: any)=>void]{letresolve: (value?: T|PromiseLike<T>)=>void;letreject: (reason?: any)=>void;constpromise=newPromise<T>((resolve_,reject_)=>{resolve=resolve_;reject=reject_;});return[promise,resolve!,reject!];}Error: |
Ron Buckton (rbuckton)
commented
Sep 8, 2020
Yes, this is a breaking change, but one that is a change in correctness that adds type-safety. The prior definition was unsafe as it allowed you to pass Above, you would need to change CC Daniel Rosenwasser (@DanielRosenwasser) to document in the 4.1 release notes that this is a breaking change intended to improve type safety. |
There has been typescript changes, where the value is required in the resolve callback for a new Promise. When resolve is called without arguments, we need to specify type void on the new Promise. More information: microsoft/TypeScript#39817
There has been typescript changes, where the value is required in the resolve callback for a new Promise. When resolve is called without arguments, we need to specify type void on the new Promise. More information: microsoft/TypeScript#39817
There has been typescript changes, where the value is required in the resolve callback for a new Promise. When resolve is called without arguments, we need to specify type void on the new Promise. More information: microsoft/TypeScript#39817
Motivation: in this version of TS, the optionality of the value passed to the Promise resolve callback does not exist. For that reason, the value passed to `resolved` is required. It can still be omitted by creating a `new Promise<void>` which is what is being done here. Read more: microsoft/TypeScript#39817
James Bromwell (thw0rted)
commented
Dec 14, 2020
I just upgraded to 4.1, and I'm trying to follow the conversation here and at #40231 and #41497. My main problem is that, in code like this: constp=newPromise<number|undefined>(resolve=>{if(Math.random()>0.5){resolve(1);}else{resolve();}});the type of I think we're stuck changing our style guide to allow passing |
Omar Diab (osdiab)
commented
Dec 16, 2020
I have this code in my codebase: it doesn't actually parameterize |
This makes
valuerequired in theresolvecallback for a newPromise. This shouldn't affect the ability to callresolve()without an argument when creating anew Promise<void>, as we already have logic in place that allows us to parameters whose types arevoidas optional.Fixes#36749