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 TypeScript definition file #176

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open

Add TypeScript definition file #176

wants to merge 27 commits into from

Conversation

philschatz
Copy link
Owner

@philschatz philschatz commented May 30, 2017

This adds a TypeScript definition file (see ./types/index.d.ts) for Octokat.

You can test it out by doing the following:

  • copy the ./types/index.d.ts file into your project by putting it in /local-types/octokat/index.d.ts
  • add the following to /tsconfig.json:
{
  "compilerOptions": {
    "typeRoots": [
      "./local-types/"
    ],
...

TODO

  • offer dot-completion (ie octo.repos('philschatz', 'octokat.js').issues(3).comments)
  • validate all arguments to all the verb methods (ie .fetch(...), .update(...))
  • yield a typed result when the Promise is resolved (instead of Promise<any>)
    • this last item requires manually documenting the result of each request
  • generate the Regular Expression validator from the JSON files
  • generate the list of valid children from the JSON files (the repos and issues in octo.repos(...).issues.fetch()
  • maybe write the autogenerated tests in TypeScript (to get some typechecking for free!)

Examples

This shows that the request is typed (via dot-completion in Atom):

image

This shows that the server response is also typed (via dot-completion in Atom):

image

@@ -4,6 +4,7 @@
"description": "Javascript GitHub client for NodeJS or a browser using promises or callbacks",
"main": "index.js",
Copy link

Choose a reason for hiding this comment

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

Can you add types field like "types": "./types/index.d.ts"?

Including declarations in your npm package
https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html

Copy link
Owner Author

Choose a reason for hiding this comment

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

Thank you for catching that oversight. Updated 😄

@atrauzzi
Copy link

What's the current status of this? Would love to see typing information available!

@romdim
Copy link

romdim commented Feb 16, 2021

Any update on this? I tried it now and it fails (types are not consistent with the actual commands)

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.

None yet

4 participants