weixin_39725193
weixin_39725193
2020-12-09 06:44

Type definitions

This adds type definitions for TypeScript.

To do:

  • [x] I think it's a good idea to track index.d.ts in git and generate it before publishing the package. I've tracked the file but left to do is running the script to generate it on prepublish
  • [x] There are a few things commented out in the type definition file
  • [x] Test this with probot. PR here https://github.com/probot/probot/pull/832

Screenshots:

screen shot 2018-12-20 at 12 33 07 screen shot 2018-12-20 at 12 33 25 screen shot 2018-12-20 at 12 33 49 screen shot 2018-12-20 at 12 34 01

该提问来源于开源项目:octokit/webhooks.js

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

6条回答

  • weixin_39725193 weixin_39725193 5月前

    -c I've just made a commit to define the payload types first and then define the method signatures so you can use the types outside those methods signatures. Example of payload definition: https://github.com/octokit/webhooks.js/pull/53/files#diff-b52768974e6bc0faccb7d4b75b162c99R8

    Nevertheless maybe you can take a look to the generate-types.js file to see how types are generated and do something similar. Basically it reads the examples from the JSON file and uses /type-writer to generate typescript definitions from those examples.

    点赞 评论 复制链接分享
  • weixin_39719727 weixin_39719727 5月前

    I think it's a good idea to track index.d.ts in git and generate it before publishing the package. I've tracked the file but left to do is running the script to generate it on prepublish

    We could run the script automatically when /webhooks is updated: https://github.com/octokit/webhooks.js/blob/cd16d7dbf38dca77d24b7f00739dc6e54e39853b/.travis.yml#L35

    I don’t mind tracking the index.d.ts file but please add a very big comment on top making clear that this file is generated, otherwise folks will start sending pull requests against it :)

    点赞 评论 复制链接分享
  • weixin_39636610 weixin_39636610 5月前

    I've been looking around at the examples on GitHub's docs, and some examples come with an example that doesn't include everything.

    For example, in the check_run event's payload the check_suite.pull_requests property is incomplete, and thus would lead to incomplete types here.

    点赞 评论 复制链接分享
  • weixin_39725193 weixin_39725193 5月前

    that's not great... Nevertheless you can always cast to any and it will be better than no having type definitions at all, I think.

    other than that, I think this is ready. I have also a local branch of probot that works with these changes.

    点赞 评论 复制链接分享
  • weixin_39719727 weixin_39719727 5月前

    Test this with probot, removing the need for this file https://github.com/probot/probot/blob/master/src/%40types/%40octokit/webhooks/index.d.ts

    Could you check ’s feedback and update / remove the file above? It’d be great to make this update as part of the Probot v8 beta release: https://github.com/probot/probot/pull/826

    点赞 评论 复制链接分享
  • weixin_39915078 weixin_39915078 5月前

    :tada: This PR is included in version 5.2.0 :tada:

    The release is available on: - npm package ( dist-tag) - GitHub release

    Your semantic-release bot :package::rocket:

    点赞 评论 复制链接分享

相关推荐