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

Add first pass at response typings #563

Closed
wants to merge 2 commits into from

Conversation

neekolas
Copy link

Summary

Adds auto-generated response types for all API methods. Typings are generated based on the public JSON schema, so it is only as complete as that schema is. Addresses #509. Does not make any adjustments to runtime code.

Not entirely sure how strict you want to be on the cases where there is incomplete data. Master currently shows a typescript error any time you try and access an API response property directly, which I took as a hint and erred on the side of strictness. I cannot find any cases where Typescript throws an error or warning on my branch that doesn't also get a warning or error in master.

It wouldn't let me commit without resolving a few unrelated tslint errors. I went through your .tslint.json and you guys have no-redundant-jsdoc turned on - so I think I was fixing a lint error and not creating one - but it's entirely possible there's something mismatched in my local environment to yours that is triggering it for me.

Requirements (place an x in each [ ])

@CLAassistant
Copy link

CLAassistant commented May 16, 2018

CLA assistant check
All committers have signed the CLA.

@codecov
Copy link

codecov bot commented May 16, 2018

Codecov Report

Merging #563 into master will not change coverage.
The diff coverage is 84%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #563   +/-   ##
=======================================
  Coverage   81.72%   81.72%           
=======================================
  Files           6        6           
  Lines         279      279           
  Branches       43       43           
=======================================
  Hits          228      228           
  Misses         36       36           
  Partials       15       15
Impacted Files Coverage Δ
src/WebClient.ts 84.24% <84%> (ø) ⬆️

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 b257599...64e7c76. Read the comment docs.

(options?: MethodArguments & AuxiliaryArguments): Promise<ResponseType>;
(
options: MethodArguments & AuxiliaryArguments,
callback: WebAPIResultCallback,
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe WebAPIResultCallback needs a generic type constraint of ResponseType?

@@ -0,0 +1,2430 @@
export interface Im {
Copy link
Contributor

Choose a reason for hiding this comment

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

could some of these interfaces be unified with interfaces defined in src/methods.ts? i know that these define the API outputs, and those the API inputs. unifying them could come with the potential win that similar structures only need to be updated in one place. keeping them separate comes with the win of decoupling. just food for thought at this point.

@aoberoi
Copy link
Contributor

aoberoi commented May 19, 2018

whoa, thanks for this contribution! i'm so glad you're willing to help further the goals of #509 (and more general #496)

i think this approach is very nice. i like that method types and response types don't directly depend on one another, and that the WebClient actually pairs them up.

you said this output was generated, would you mind sharing the script? i think it would be useful to keep in the repo to "sync" with the OpenAPI spec every once in a while. was there much manual manipulation of the output after the script was run? i'm really interested in understanding the process.

reviewing a change this big will definitely take some time. i'd like to build the package and try using it locally to see what the typescript language service has to offer with all these awesome types to work with! i don't expect to have time to do this in the next week or so. i encourage other community members to check out this patch and leave some feedback.

since i see this as a change that might take some iteration before landing, and since potentially more people may like to get involved, perhaps it makes sense to retarget this PR onto a new feature branch (e.g. feat-webclient-response-types). that way this PR could land on that branch and others could make additional PRs to continue to add polish. @neekolas wdyt?


i saw that you tried to undo the style changes introduced by prettier, thanks. the majority of the style changes i'd probably want to revert before this lands on master. some were great though, and i think we can contribute some changes to our tslint rules to enforce them! happy to have that discussion in a separate PR or issue.

@aoberoi
Copy link
Contributor

aoberoi commented May 19, 2018

@clavin i'd love to hear your thoughts, if you have a chance.

@aoberoi aoberoi mentioned this pull request Jun 12, 2018
9 tasks
@9renpoto
Copy link

9renpoto commented Nov 19, 2018

@neekolas Hi. If you do not have a problem, could you please rebase it ? 👍

refs: neekolas#2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants