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

Update Promise definition #30268

Merged
merged 5 commits into from
Aug 18, 2017
Merged

Conversation

rbuckton
Copy link
Member

@rbuckton rbuckton commented Jul 7, 2017

As a follow up to #30216 (comment), this updates the definition of Promise in winjs.base.d.ts to use type parameter defaults and addresses errors in several files where either TypeScript could not pick the correct type or where the code using the promise was trying to force the wrong type (e.g. trying to explicitly force a TPromise<Something> into a TPromise<void>).

@msftclas
Copy link

msftclas commented Jul 7, 2017

@rbuckton,
Thanks for your contribution as a Microsoft full-time employee or intern. You do not need to sign a CLA.
Thanks,
Microsoft Pull Request Bot

@rbuckton
Copy link
Member Author

rbuckton commented Jul 7, 2017

// CC: @mjbvz

@mjbvz mjbvz self-assigned this Jul 7, 2017
@mjbvz mjbvz requested a review from jrieken July 7, 2017 21:37
@jrieken
Copy link
Member

jrieken commented Jul 10, 2017

@microsoft/vscode everyone should take a quick look at this

@chrmarti
Copy link
Contributor

chrmarti commented Jul 10, 2017

I see a few additional <any>s, looks good otherwise.

@rbuckton
Copy link
Member Author

Most of the changes outside of winjs.base.d.ts and monaco.d.ts were adding explicit type annotations in a few places where TypeScript could not determine the correct type.

There are only 3 places where I changed runtime behavior:

All three cases were added to correctly set the resolved value based on the expected return type of the containing method. In all three instances a TPromise<void> was expected; however, in each case the resulting Promise could resolve to an actual value, so the result would not have actually been a TPromise<void>. In each case, I added a .then(() => { /* drop resolved value */ }) which would explicitly drop the resolved value of the antecedent and ensure a correct void return type.

Alternatively, I can change the return type of the three methods above to something like a TPromise<void | X> or TPromise<any> to avoid any changes to actual runtime emit, but with possibly reduced type safety. I felt the additional continuation more correctly illustrated the intent.

@rbuckton
Copy link
Member Author

Also note, I just submitted microsoft/TypeScript#17077, which I hope to discuss at the next TypeScript design meeting. If we decide to accept that change for TypeScript 2.5, we could further improve the Promise implementation in VSCode as TypeScript would do a better job inferring the correct return types in some of your more complex promise chains.

@dbaeumer
Copy link
Member

Wasn't aware that you can have default values for generic parameters. Cool.

@jrieken jrieken requested review from sandy081 and removed request for jrieken July 11, 2017 10:37
@jrieken
Copy link
Member

jrieken commented Jul 11, 2017

Assigning @sandy081 - the runtime changes as listed here affect your code if I am not mistaken. From my side this looks good

@rbuckton
Copy link
Member Author

@sandy081
Copy link
Member

@rbuckton It makes sense to me dropping the values in following

You can also resolve to null in these cases.then(() => null). I think this is what we do when we resolve a promise returningvoid.

I would ask @chrmarti to confirm the change (assigning @chrmarti)

@sandy081 sandy081 requested review from chrmarti and removed request for sandy081 July 11, 2017 18:46
@rbuckton
Copy link
Member Author

@sandy081 we treat null, undefined, and void differently in the compiler, though that isn't always evident if you are not using --strictNullChecks. I'm generally wary of using null due to the fact that typeof null === "object". Also, () => {} is fewer characters than () => {}, though I added the comment to explain the rationale.

@sandy081
Copy link
Member

@rbuckton Good to know.

@mjbvz
Copy link
Collaborator

mjbvz commented Aug 16, 2017

@rbuckton Sorry, this fell off my radar. Can you resolve the merge conflicts so we can merge this in. I can also take the PR if you'd prefer

@mjbvz
Copy link
Collaborator

mjbvz commented Aug 17, 2017

Looks like the latest iteration has a few build errors: https://travis-ci.org/Microsoft/vscode/jobs/265409458

@rbuckton
Copy link
Member Author

Yeah, I just noticed that. It is building cleanly locally. I'll look into it.

@rbuckton
Copy link
Member Author

rbuckton commented Aug 17, 2017

I'm trying to make sure I have the correct dependencies in node_modules and have been running into issues. I deleted node_modules and ran scripts\npm.bat install and I'm getting the following errors when installing oniguruma@6.1.1 as a dependency:

Creating library C:\dev\vscode\node_modules\oniguruma\build\Release\onig_scanner.lib and object C:\dev\vscode\node_modules\oniguruma\build\Release\onig_scanner.exp
onig-result.obj : error LNK2001: unresolved external symbol onig_region_free [C:\dev\vscode\node_modules\oniguruma\build\onig_scanner.vcxproj]
onig-reg-exp.obj : error LNK2001: unresolved external symbol onig_search [C:\dev\vscode\node_modules\oniguruma\build\onig_scanner.vcxproj]
onig-reg-exp.obj : error LNK2001: unresolved external symbol OnigEncodingUTF8 [C:\dev\vscode\node_modules\oniguruma\build\onig_scanner.vcxproj]
onig-reg-exp.obj : error LNK2001: unresolved external symbol onig_free [C:\dev\vscode\node_modules\oniguruma\build\onig_scanner.vcxproj]
onig-reg-exp.obj : error LNK2001: unresolved external symbol OnigDefaultSyntax [C:\dev\vscode\node_modules\oniguruma\build\onig_scanner.vcxproj]
onig-reg-exp.obj : error LNK2001: unresolved external symbol onig_error_code_to_str [C:\dev\vscode\node_modules\oniguruma\build\onig_scanner.vcxproj]
onig-reg-exp.obj : error LNK2001: unresolved external symbol onig_region_new [C:\dev\vscode\node_modules\oniguruma\build\onig_scanner.vcxproj]
onig-reg-exp.obj : error LNK2001: unresolved external symbol onig_new [C:\dev\vscode\node_modules\oniguruma\build\onig_scanner.vcxproj]
C:\dev\vscode\node_modules\oniguruma\build\Release\onig_scanner.node : fatal error LNK1120: 8 unresolved externals [C:\dev\vscode\node_modules\oniguruma\build\onig_scanner.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\Microsoft Visual Studio\Preview\Enterprise\MSBuild\15.0\Bin\MSBuild.exe` failed with exit code: 1

I'm using node v8.1.4, npm 5.3.0, and Visual Studio 2015

@roblourens
Copy link
Member

You might also want to delete stuff in .build and elsewhere, I sometimes have to git clean -xfd when updating dependencies. Also we are mostly still on npm 4.x so you might want to try that too.

@mjbvz mjbvz merged commit 066a2bb into microsoft:master Aug 18, 2017
@mjbvz mjbvz added this to the August 2017 milestone Aug 18, 2017
@github-actions github-actions bot locked and limited conversation to collaborators Mar 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants