Skip to content
This repository has been archived by the owner on Jul 10, 2019. It is now read-only.

Tweak withClientState signature to work around typescript bug #165

Conversation

Phoenixmatrix
Copy link

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.

@apollo-cla
Copy link

@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/

@Phoenixmatrix
Copy link
Author

Phoenixmatrix commented Jan 6, 2018

(I want to say the current build failure is because the npm registry is currently sad. It will probably work later.)

Copy link
Contributor

@fbartho fbartho left a 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.

@Phoenixmatrix
Copy link
Author

Someone with write access should be able to just kick it off? Alternatively I can close and reopen the PR.

@codecov-io
Copy link

Codecov Report

Merging #165 into master will increase coverage by 0.06%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
packages/apollo-link-state/src/index.ts 96.42% <100%> (+0.06%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b865c6d...0aebfef. Read the comment docs.

@fbartho fbartho self-requested a review January 7, 2018 19:52
Copy link
Contributor

@fbartho fbartho left a 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!

Copy link
Member

@peggyrayzis peggyrayzis left a 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!

@peggyrayzis peggyrayzis merged commit 668c7d0 into apollographql:master Jan 8, 2018
@wearethefoos
Copy link

Nice! @peggyrayzis @fbartho any chance this will be released soon? 🙏 😄

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.

[typescript] Issue with generated .d.ts for withClientState
6 participants