Tweak withClientState signature to work around typescript bug #165
Tweak withClientState signature to work around typescript bug #165
Conversation
@Phoenixmatrix: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Meteor Contributor Agreement here: https://contribute.meteor.com/ |
(I want to say the current build failure is because the npm registry is currently sad. It will probably work later.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me; does anybody know how to kick travis so it tries the build again? NPM claims the issues are resolved.
Someone with write access should be able to just kick it off? Alternatively I can close and reopen the PR. |
Codecov Report
@@ Coverage Diff @@
## master #165 +/- ##
==========================================
+ Coverage 95.58% 95.65% +0.06%
==========================================
Files 2 2
Lines 68 69 +1
Branches 18 18
==========================================
+ Hits 65 66 +1
Misses 3 3
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had the power to kick!
Looks good to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making this fix!
Nice! @peggyrayzis @fbartho any chance this will be released soon? 🙏 😄 |
Resolves #158
This is a non-ideal fix for #158, related on a TypeScript issue that should be fixed, but apparently is not (microsoft/TypeScript/issues/8681). The relevent comment in that issue is this one
The typescript code in apollo-link-state is perfectly fine and would work as is, but the generated type definition, after compilation is:
export declare const withClientState: ({resolvers, defaults, cache}?: ClientStateConfig)
With strict null enabled, you'll get an error message because it is impossible to destructure the fields when the object is nullable (because of the
?
after the curly brace). At runtime this isn't an issue since withClientState's argument has a default value.This PR changes the signature to "trick" the compiler a little: by doing the destructuring inside of the function, the generated
.d.ts
will not have destructuring, and the problem goes away.It's not great to have to do this, but typescript with strict null is sooooooooo good, it's hard to give up :)
I'll follow up by opening a new issue on the typescript repo, but history has shown issues like that can take a long time to get fixed there.