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

Upgrade TS to 3.7.3 #3618

Merged
merged 3 commits into from
Dec 17, 2019
Merged

Upgrade TS to 3.7.3 #3618

merged 3 commits into from
Dec 17, 2019

Conversation

trevor-scheer
Copy link
Member

@trevor-scheer trevor-scheer commented Dec 17, 2019

This commit updates our typescript version to latest. It also incorporates related fixes (read: workarounds?) that have blocked the upgrade since 3.6.3. I haven't yet been able to identify the underlying issue, but this seems like a TS regression that's over my head.

The symptom is that within each of our invoke* functions, method is no longer benefiting from the typeof method === 'function' check. Within the if block, method is being inferred as a T[TMethodName] rather than a T[TMethodName] & Function - hence method.apply was now considered invalid (as method is no longer also a Function according to TS).

The fixes proposed here do limit some of the genericness of the Dispatcher class and its functions, however I'd argue that the level of said genericness is unnecessary.

  • The Dispatcher really only needs to accept a GraphQLListener
  • A GraphQLListener only has methods for properties, so the hoops we previously jumped through to collect the names of strictly function properties on an object seem unnecessary and are nicely simplified by keyof T.

It's worth mentioning a couple things:

  • No type inference is lost where we consume Dispatcher. Autocomplete still smartly suggests the allowed function names of a GraphQLListener as we would hope.
  • The types being modified don't exist in the public API, so we shouldn't have any concerns with breaking type changes to the Dispatcher class.

This commit updates our typescript version to latest. It also
incorporates related fixes (workarounds?) that have blocked
the upgrade since 3.6.3. I haven't yet been able to identify
the underlying issue, nor do I think it's worth my time at this
point.

The fixes proposed here do limit some of the generic-ness of the
Dispatcher class and its functions, however I'd argue that the
level of said generic-ness is unnecessary.

* The Dispatcher really only needs to accept a GraphQLListener
* A GraphQLListener _only_ has methods for properties, so the
  hoops we previously jumped through to collect the names of
  strictly function properties on an object is unnecessary and
  greatly simplified by 'keyof T'.

It's worth mentioning a couple things:

* No type inference is lost where we consume Dispatcher.
  Autocomplete still smartly suggests the allowed function
  names of a GraphQLListener as we would hope
* The types being modified don't exist in the public API, so
  we shouldn't have any concerns with breaking type changes
  to the Dispatcher class.
Copy link
Member

@abernix abernix left a comment

Choose a reason for hiding this comment

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

Thank you for looking into this!

@trevor-scheer trevor-scheer merged commit 1169db6 into master Dec 17, 2019
@trevor-scheer trevor-scheer deleted the trevor/typescript-3.7.x branch December 17, 2019 18:14
@abernix abernix added this to the Release 2.9.15 milestone Dec 18, 2019
abernix added a commit that referenced this pull request May 6, 2020
As I reached to introduce a dispatcher for an interface that wasn't a
`GraphQLRequestListener`, it dawned on me that the dispatcher that we
already had was pretty close to being correct for this prior to the changes
in the linked PR/commits below ([[Ref 1]][[Ref 2]]).

Within those changesets, the addition of `GrahpQLRequestListener` as a
constraint to the `Dispatcher`'s `T` type was done as a matter of necessity
so TypeScript could be updated to the latest version.

Further analysis, with a motivation to boot, led me to believe that
TypeScript was correct in its newfound determination (circa ~v3.7.3) that
the `apply` method didn't exist on the keys of the interface being invoked.

Concretely, I'm pretty sure there was no constraint that was actually
ensuring they were functions and some degree of indirection caused
TypeScript to give up trying to reconcile that.

This brings back a generic property to the `Dispatcher` by using an object
with `string`-key'd properties and functions as values as the constraint for
the entire `Dispatcher` interface, rather than `GraphqLRequestListener`
itself.

Ref 1: 1169db6
Ref 2: #3618
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2023
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.

2 participants