Giter Club home page Giter Club logo

types.ts's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

types.ts's Issues

Deriving Typescript definitions directly from GitHub's OpenAPI Schema

The way it currently works is this:

  1. We don't load the OpenAPI schema directly. Instead, we use the github-openapi-graphql-server.
  2. We query for the endpoint parameter types and response schemas.
  3. github-openapi-graphql-server is using the de-referenced OpenAPI schema under the hood. And we don't read out the JSON Schemas for the response, instead we read out the examples and derive the types from that: https://github.com/gr2m/github-openapi-graphql-server/blob/c2cc33ce46a3ac870680cd889d106e51329b5e9f/lib/definition-to-endpoint.js#L124-L151. This has historical reasons, it's coming from a time where JSON Schemas were not available.

All this results in incomplete types, especially for reponses. See for example:

The current setup also prevents us from taking advantage of the $ref statements in GitHub's OpenAPI schema in order to greatly reduce duplications in the Type definitions for both endpoint parameters and responses.

Moving forward, I would do the following:

  1. In github-openapi-graphql-server, add a way to query what version of the published OpenAPI spec was used, so that it can be loaded independently from the query response.
  2. Load the JSON schema file that is not de-referenced and use it to derive all types for both, the parameters and responses.
  3. Put it all together into scripts/update-endpoints/typescript.js.

I've yet do do a thorough research about turning JSON API / JSON Schema to TypeScript definition. I'm optimistic that there are options out there that can do the heavy lifting, but we shall see. I'm open to ideas.

I'm not yet sure how 3. will work, exactly. I'll update this issue as soon as I have a clear picture on how it could work

An in-range update of @octokit/graphql is breaking the build 🚨


🚨 Reminder! Less than one month left to migrate your repositories over to Snyk before Greenkeeper says goodbye on June 3rd! 💜 🚚💨 💚

Find out how to migrate to Snyk at greenkeeper.io


The devDependency @octokit/graphql was updated from 4.3.1 to 4.4.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@octokit/graphql is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • test: There are 1 failures, 0 warnings, and 0 notices.

Release Notes for v4.4.0

4.4.0 (2020-05-07)

Bug Fixes

  • package: update universal-user-agent to version 5.0.0 (6223d69)

Features

  • add mediaType to non variable options (#84) (f04c0e1)
FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Export GetResponseDataType & GetResponseType helpers

This is a follow up to https://github.com/octokit/rest.js/issues/1624#issuecomment-590436498, octokit/plugin-rest-endpoint-methods.js#47

What’s missing?

Example

import { GetResponseDataType } from "@octokit/types"
import { Octokit } from "@octokit/core";
import { restEndpointMethods } from "./src";

const MyOctokit = Octokit.plugin(restEndpointMethods);
const octokit = new MyOctokit()

type CreateLabelResponseDataType = GetResponseDataType<typeof octokit.issues.createLabel>

Why?

@octokit/rest v16 exported response types, v17 does not. There is a separate issue to export response types (#25). This issue is about exporting helper methods that allow to derive a response type from the REST API endpoint methods.

Alternatives you tried

Put the code inline, it's fairly trivial

type Unwrap<T> = T extends Promise<infer U> ? U : T;
type AnyFunction = (...args) => any
type GetResponseType<T extends AnyFunction> = Unwrap<ReturnType<T>>;
type GetResponseDataType<T extends AnyFunction> = Unwrap<ReturnType<T>>["data"];

error TS6133: 'Url' is declared but its value is never read.

@octokit/[email protected]

What happened?

> tsc --noEmit

node_modules/@octokit/types/src/generated/Endpoints.ts:4:1 - error TS6133: 'Url' is declared but its value is never read.

4 import { Url } from "../Url";
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Found 1 error.

What did you expect to happen?

No error

What the problem might be

Generated unused import

Related to #36

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this 💪.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


No npm token specified.

An npm token must be created and set in the NPM_TOKEN environment variable on your CI environment.

Please make sure to create an npm token and to set it in the NPM_TOKEN environment variable on your CI environment. The token must allow to publish to the registry https://registry.npmjs.org/.


Good luck with your project ✨

Your semantic-release bot 📦🚀

Use TypeSript's Date type

What’s missing?
This module doesn't take advantage of the TypeScript's Date type and instead uses string.

Why?
To be able to natively take advantage of all the methods that comes with the Date type.

Alternatives you tried
If I wanted to use Date methods I would have to some manual parsing.

regression: unused import causing downstream typecheck failure

What happened?
After upgrading to 2.11.0, my build started failing with:

> tsc --noEmit
node_modules/@octokit/types/src/RequestInterface.ts:2:1 - error TS6133: 'EndpointOptions' is declared but its value is never read.
2 import { EndpointOptions } from "./EndpointOptions";
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

What did you expect to happen?
Pass type checking when imported from my project, even if my tsconfig.json is strict.

What the problem might be
My tsconfig.json file has the following 4 strict options turned on:

  • noUnusedLocals
  • noUnusedParameters
  • noImplicitReturns
  • noFallthroughCasesInSwitch

@octokit/types is published as .ts files, which causes my typescript to check it (using my tsconfig.json) when imported via node_modules.

Workaround: remove unused import and republish.
More permanent solutions (to avoid similar issues):

  • add a tsconfig.json to repo with strict options all turned on. this way, you'd know code is compatible.
  • build package using tsc and publish the .d.ts files.

Response types have optional keys

Endpoints["PUT /repos/{owner}/{repo}/contents/{path}"]["response"]["data"]["content"] // can be undefined

This is a problem with the Official OpenAPI specs, see e.g.

Many response types seem to be affected, not all however. E.g. Endpoints["GET /repos/{owner}/{repo}"]["response"]["data"] has the correct types.

Until this problem is resolved on GitHub's side, we could recursively make all response properties non-optional

Define a type for items in "SearchIssuesAndPullRequestsResponseData" type.

The property items in the type SearchIssuesAndPullRequestsResponseData doesn't have it's own exported type. it would be nice to have that type defined and exported so we can use in some helpers methods.

For now I'm copy/pasting the code from 'generated/endpoints.ts` and creating the type in my code.

Maybe there is another workaround, but I couldn't find anything.

"Cannot find module 'http'" when using with Angular

I'm trying to use the octokit rest, with my Angular app, but when compiling, the TypeScript compiler throws an error:

ERROR in node_modules/@octokit/types/src/RequestRequestOptions.ts:1:23 - error TS2307: Cannot find module 'http'.

    1 import { Agent } from "http";
                            ~~~~~~

I assume, it comes from the fact, that the RequestRequestOptions.ts file is trying to import from a node.js http module. The error comes off, when I manually remove the part of file, which causes the error.

Unknow type of pull_requests in ActionsGetWorkflowRunResponseData

What happened?

  const workflow_run: OctokitResponse<ActionsGetWorkflowRunResponseData> = await octokit.actions.getWorkflowRun({
    owner: context.repo.owner,
    repo: context.repo.repo,
    run_id: context.runId
  })

console.log(workflow_run.data.pull_requests[0].number) // => TS2571: Object is of type 'unknown'

What did you expect to happen?

It works!

What the problem might be

pull_requests: unknown[]; instead of

  pull_requests: {
    url: string;
    id: number;
    number: number;
    head: {
      ref: string;
      sha: string;
      repo: {
        id: number;
        url: string;
        name: string;
      };
    };
    base: {
      ref: string;
      sha: string;
      repo: {
        id: number;
        url: string;
        name: string;
      };
    };

as in ChecksCreateResponseData, for example.

Probably will be fixed by #161, but I'm not sure.

"GET /repos/{owner}/{repo}/commits" seems to have the wrong type for the commit field

Version

    "@octokit/rest": "^18.0.14",
    "@octokit/webhooks": "^7.21.0"

What happened?

Endpoints["GET /repos/{owner}/{repo}/commits"]["response"] does not match what's actually returned in the endpoint. As an evidence, see: https://api.github.com/repos/octokit/types.ts/commits. For instance, it's missing the parents field.

The correct type for the items looks like StatusEvent["commit"] from https://github.com/octokit/webhooks/blob/fc8d5d284f936a5cddb952816f692fb4239edf7b/schema.d.ts#L7546.

Dependency Dashboard

This issue contains a list of Renovate updates and their statuses.

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to ignore the schedule.

  • fix(deps): lock file maintenance

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.


  • Check this box to trigger a request for Renovate to run again on this repository

error TS7019: Rest parameter 'args' implicitly has an 'any[]' type.

@octokit/[email protected]

What happened?

> tsc --noEmit

node_modules/@octokit/types/src/GetResponseTypeFromEndpointMethod.ts(2,21): error TS7019: Rest parameter 'args' implicitly has an 'any[]' type.

$ npm ls @octokit/types
[email protected] /home/huan/git/osschat
└─┬ [email protected]
  ├─┬ @octokit/[email protected]
  │ └── @octokit/[email protected] 
  ├─┬ @octokit/[email protected]
  │ ├─┬ @octokit/[email protected]
  │ │ └── @octokit/[email protected]  deduped
  │ └── @octokit/[email protected]  deduped
  ├─┬ @octokit/[email protected]
  │ └── @octokit/[email protected]  deduped
  ├─┬ @octokit/[email protected]
  │ └── @octokit/[email protected]  deduped
  ├─┬ @octokit/[email protected]
  │ ├─┬ @octokit/[email protected]
  │ │ └── @octokit/[email protected]  deduped
  │ └── @octokit/[email protected]  deduped
  └─┬ @octokit/[email protected]
    ├─┬ @octokit/[email protected]
    │ └── @octokit/[email protected]  deduped
    ├─┬ @octokit/[email protected]
    │ └── @octokit/[email protected]  deduped
    ├─┬ @octokit/[email protected]
    │ └── @octokit/[email protected]  deduped
    └─┬ @octokit/[email protected]
      └── @octokit/[email protected]  deduped

What did you expect to happen?

No error

What the problem might be

Typing problem.

P.S. Could we add some unit tests to guard those problems? It's really annoying.

2.8.0 throws "Rest parameter 'args' implicitly has an 'any[]'"

What happened?

When upgrading from 2.7.1 to 2.8.0 starts throwing the following compile error:

> [email protected] compile /Users/bencoe/google/repo-automation-bots/packages/gcf-utils
> tsc -p .

node_modules/@octokit/request/node_modules/@octokit/types/src/GetResponseTypeFromEndpointMethod.ts:2:21 - error TS7019: Rest parameter 'args' implicitly has an 'any[]' type.

2 type AnyFunction = (...args) => any;
                      ~~~~~~~


Found 1 error.

What did you expect to happen?

tsc to compile the code 😆

What the problem might be

Computers 💻

Endpoints["GET /repos/{owner}/{repo}/contributors"]["response"]["data"] is unknown

What happened?

Endpoints["GET /repos/{owner}/{repo}/contributors"]["response"]["data"];
// returns "unknown",

What did you expect to happen?

Endpoints["GET /repos/{owner}/{repo}/contributors"]["response"]["data"] should be the same as

import { paths } from "@octokit/openapi-types";
paths["/repos/{owner}/{repo}/contributors"]["get"]["responses"]["200"]["application/json"];

Similar issue as #219

Export IssuesUpdateEndpoint

This type is defined, but is not exported. It would be nice have it exported so we can use it to type some helper methods.

Right now I'm copy/pasting the type from generated/endpoints.ts which is not the best solution.

Distributing typescript files breaks pkg bundling

What happened?

In Octokit v16 we were able to successfully use pkg by zeit to create binaries of https://github.com/intuit/auto/.

After the v17 upgrade we started getting this error while trying to run pkg.

Screen Shot 2020-05-18 at 10 51 27 AM

What did you expect to happen?

Pkg runs without complaining about uncompiled typescript files

What the problem might be

I'm pretty sure this is because this package publishes uncompiled typescript. I think pkg works by walking through the main of each included module and does it's magic.

I think this package should follow the same structure as a definitely typed package.

  • distribute only .d.ts files
  • "main": "",
  • "types": "dist/index.d.ts",

`author_association` missing from pull request review type.

What happened?

I have these types:

import * as github from '@actions/github'
export type Octokit = ReturnType<typeof github.getOctokit>
export type Review = GetResponseDataTypeFromEndpointMethod<Octokit['pulls']['getReview']>

The documentation (https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls#get-a-review-for-a-pull-request) says there should be a author_association: string field on this type.

The type Review above contains all fields listed in the documentation up to commit_id, as seen in this error:

Type '{ id: number; node_id: string; user: { login: string; id: number; node_id: string; avatar_url: string; gravatar_id: string; url: string; html_url: string; followers_url: string; following_url: string; gists_url: string; starred_url: string; subscriptions_url: string; organizations_url: string; repos_url: string; events_url: string; received_events_url: string; type: string; site_admin: boolean; }; body: string; state: string; html_url: string; pull_request_url: string; _links: { html: { href: string; }; pull_request: { href: string; }; }; submitted_at: string; commit_id: string; }' has no properties in common with type '{ author_association?: string | undefined; }'.

What did you expect to happen?

I expected this type to have a author_association: string field.

Endpoints["GET /repos/{owner}/{repo}/issues"]["response"]["data"] is unknown

What happened?

Endpoints["GET /repos/{owner}/{repo}/issues"]["response"]["data"];
// returns "unknown",

What did you expect to happen?

Endpoints["GET /repos/{owner}/{repo}/issues"]["response"]["data"] should be the same as

import { paths } from "@octokit/openapi-types";
paths["/repos/{owner}/{repo}/issues"]["get"]["responses"]["200"]["application/json"];

What the problem might be

I'm investigating.

Bug in README.md sample?

In the sample, shouldn't it use GetResponseDataTypeFromEndpointMethod and GetResponseTypeFromEndpointMethod instead of GetResponseType and GetResponseDataType ?

Below is the current version:

import {
  GetResponseTypeFromEndpointMethod,
  GetResponseDataTypeFromEndpointMethod,
} from "@octokit/types";
import { Octokit } from "@octokit/rest";

const octokit = new Octokit();
type CreateLabelResponseType = GetResponseType<
  typeof octokit.issues.createLabel
>;
type CreateLabelResponseDataType = GetResponseDataType<
  typeof octokit.issues.createLabel
>;

`Endpoints["GET /repos/{owner}/{repo}/commits/{ref}"]` response type is incomplete

What happened?

Endpoints["GET /repos/{owner}/{repo}/git/commits/{commit_sha}"] has no files field in response type.

What did you expect to happen?

It has files field.

What the problem might be

Content in openapi-types is "application/json": components["schemas"]["git-commit"];, I suppose it should be "application/json": components["schemas"]["commit"]; (which has files? field).

Incorrect type for "actions.listWorkflowRuns"

What happened?

Incorrect type of status in ActionsListWorkflowRunsEndpoint.

type ActionsListWorkflowRunsEndpoint = {
owner: string;
repo: string;
workflow_id: number;
/**
* Returns someone's workflow runs. Use the login for the user who created the `push` associated with the check suite or workflow run.
*/
actor?: string;
/**
* Returns workflow runs associated with a branch. Use the name of the branch of the `push`.
*/
branch?: string;
/**
* Returns workflow run triggered by the event you specify. For example, `push`, `pull_request` or `issue`. For more information, see "[Events that trigger workflows](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows)" in the GitHub Help documentation.
*/
event?: string;
/**
* Returns workflow runs associated with the check run `status` or `conclusion` you specify. For example, a conclusion can be `success` or a status can be `completed`. For more information, see the `status` and `conclusion` options available in "[Create a check run](https://developer.github.com/v3/checks/runs/#create-a-check-run)."
*/
status?: "completed" | "status" | "conclusion";
/**
* Results per page (max 100)
*/
per_page?: number;
/**
* Page number of the results to fetch.
*/
page?: number;
};

status?: "completed" | "status" | "conclusion";

https://developer.github.com/v3/actions/workflow-runs/#list-workflow-runs

Returns workflow runs associated with the check run status or conclusion you specify. For example, a conclusion can be success or a status can be completed. For more information, see the status and conclusion options available in "Create a check run."

Create a check run

https://developer.github.com/v3/checks/runs/#create-a-check-run

Name Type Description
status string The current status. Can be one of queued, in_progress, or completed. Default: queued
conclusion string Required if you provide completed_at or a status of completed. The final conclusion of the check. Can be one of success, failure, neutral, cancelled, skipped, timed_out, or action_required. When the conclusion is action_required, additional details should be provided on the site specified by details_url.Note: Providing conclusion will automatically set the status parameter to completed. Only GitHub can change a check run conclusion to stale.

What did you expect to happen?

I think the status below should be included.

  • queued
  • in_progress
  • completed
  • success
  • failure
  • ...
  • action_required

What the problem might be

I couldn't specify in_progress status.

Typings for /user/repos

What’s missing?
Typings for the /user/repos endpoint response.

Why?
It's currently missing and seems fitting for this project.

Alternatives you tried
Typing it myself, not that hard, but a little inconvenient, as most of my GH types depend on this package.

30x redirect response type is set to `never`

What happened?

Endpoints["GET /repos/{owner}/{repo}/tarball/{ref}"]["response"] // type: never

What did you expect to happen?

Endpoints["GET /repos/{owner}/{repo}/tarball/{ref}"]["response"] // type: OctokitResponse<unknown>

What the problem might be

We only set response types for success response types which currently are:

type SuccessStatusesMap = {
  "200": 200;
  "201": 201;
  "204": 204;
};

We will need to update this code

type FirstSuccessResponse<
  R,
  S extends keyof R = keyof R
> = S extends keyof SuccessStatusesMap
  ? R[S] extends never
    ? Omit<OctokitResponse<unknown, SuccessStatusesMap[S]>, "data">
    : OctokitResponse<DataType<R[S]>, SuccessStatusesMap[S]>
  : never;

Missing types for resonse for listEventsForAuthenticatedUser

What’s missing?

Missing return types for listEventsForAuthenticatedUser. Everything is any.

Why?

Probably because there are many different events, and it might be annoying to type them all.

Alternatives you tried

Looking for sources of these events. Found that maybe webhook repo has types that can be re-used, but not directly.

Incorrect type for template_repository in ReposGetResponseData endpoint

What happened?
Incorrect type for template_repository in ReposGetResponseData endpoint.

template_repository: string;

It is currently string but should be a repository object or null.

The sample response for /repos/{owner}/{repo} shows template_repository as null. When a repository was created from a template, this field should hold the repository object for that template.

What did you expect to happen?
Instead of string, type should be a repository object similar to owner and to the template_repository returned by /repos/{template_owner}/{template_repo}/generate

`Endpoints['GET /repos/{owner}/{repo}/git/trees/{tree_sha}']` response is too relaxed

What happened?

It returns components["schemas"]["git-tree"] which has tree field defined as

tree: {
  path?: string;
  mode?: string;
  type?: string;
  sha?: string;
  size?: number;
  url?: string;
}[];

while operations["git/create-tree"] has request params defined as

tree: {
  path?: string;
  mode?: "100644" | "100755" | "040000" | "160000" | "120000";
  type?: "blob" | "tree" | "commit";
  sha?: string | null;
  content?: string;
}[];

so response type is not compatible with request one.

What did you expect to happen?

mode & type should be compatible.

What the problem might be

mode & type on components["schemas"]["git-tree"] should be more strict.

Endpoints['PATCH /repos/{owner}/{repo}/check-runs/{check_run_id}']['parameters'] gives broken types in version newer than v6.3.2

How to recreate the issue

Exactly same issues as: #274

Create a test project:

npm init -y && npm install typescript @octokit/types

Generates this package.json file:

{
  "name": "test-repo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@octokit/types": "^6.11.0",
    "typescript": "^4.2.2"
  }
}

Create test.ts:

import { Endpoints } from '@octokit/types'

type listUserReposParameters = Endpoints['PATCH /repos/{owner}/{repo}/check-runs/{check_run_id}']['parameters']

const test: listUserReposParameters = {
    name: '',
    head_sha: '',
    owner: '',
    repo: '',
    status: 'completed'
}
./node_modules/.bin/tsc test.ts

Gives the following error and the type that it constructed seems very broken:

test.ts:10:5 - error TS2322: Type 'string' is not assignable to type 'never'.

10     status: 'completed'
       ~~~~~~

  node_modules/@octokit/openapi-types/dist-types/generated/types.d.ts:19876:21
    19876                     status?: "completed";
                              ~~~~~~
    The expected type comes from property 'status' which is declared here on type '{ owner: string; repo: string; check_run_id: number; } & Partial<{ status?: "completed"; } & { [key: string]: any; }> & Partial<{ status?: "queued" | "in_progress"; } & { [key: string]: any; }> & { ...; }'


Found 1 error.

Trying with v6.3.2 works:

npm install @octokit/[email protected]
tsc test.ts

Diff is here:
v6.3.2...v6.4.0

Endpoints['POST /repos/{owner}/{repo}/check-runs']['parameters'] gives broken types in version newer than v6.3.2

How to recreate the issue

Create a test project:

npm init -y && npm install typescript @octokit/types

Generates this package.json file:

{
  "name": "test-repo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@octokit/types": "^6.11.0",
    "typescript": "^4.2.2"
  }
}

Create test.ts:

import { Endpoints } from '@octokit/types'

type listUserReposParameters = Endpoints['POST /repos/{owner}/{repo}/check-runs']['parameters']

const test: listUserReposParameters = {
    name: '',
    head_sha: '',
    owner: '',
    repo: '',
    status: 'completed'
}
tsc test.ts

Gives the following error and the type that it constructed seems very broken:

test.ts:8:5 - error TS2322: Type 'string' is not assignable to type 'never'.

8     status: 'completed'
      ~~~~~~

  node_modules/@octokit/openapi-types/dist-types/generated/types.d.ts:19740:21
    19740                     status?: "completed";
                              ~~~~~~
    The expected type comes from property 'status' which is declared here on type '{ owner: string; repo: string; } & Partial<{ status?: "completed"; } & { [key: string]: any; }> & Partial<{ status?: "queued" | "in_progress"; } & { [key: string]: any; }>'


Found 1 error.

Trying with v6.3.2 works:

npm install @octokit/[email protected]
tsc test.ts

Diff is here:
v6.3.2...v6.4.0

How to narrow down Types for a `octokit.repos.getContent()` response?

I'm trying to read the contents of a directory and the return type of octokit.repos.getContent is a type union that has many possible values.

I'm trying to narrow the return value of getContent to only one of those options, it looks like this:

"content-directory": {
    type: string;
    size: number;
    name: string;
    path: string;
    content?: string;
    sha: string;
    url: string;
    git_url: string | null;
    html_url: string | null;
    download_url: string | null;
    _links: {
        git: string | null;
        html: string | null;
        self: string;
    };
}[]

I created a type out of it:

type DirectoryItems = components["schemas"]["content-directory"];

and now I'm trying to use it in a type guard:

const { data } = await octokit.repos.getContent({
    // ...
});

if(data instanceof DirectoryItems) {

}

but it says

'DirectoryItems' only refers to a type, but is being used as a value here.

How can I narrow the type of data to make sure that it is indeed an array of "content-directory" items? Is there an example somewhere on how to use TypeScript with Octokit?

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this 💪.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Cannot push to the Git repository.

semantic-release cannot push the version tag to the branch master on the remote Git repository with URL https://x-access-token:[secure]@github.com/octokit/types.ts.

This can be caused by:


Good luck with your project ✨

Your semantic-release bot 📦🚀

204 responses should get ` OctokitResponse<never>`, not ` OctokitResponse<any>`

What happened?

Example in src/generated/Endpoints.ts

export interface Endpoints {
  /**
   * @see https://developer.github.com/v3/apps/#delete-an-installation
   */
  "DELETE /app/installations/:installation_id": {
    parameters: AppsDeleteInstallationEndpoint;
    request: AppsDeleteInstallationRequestOptions;
    response: OctokitResponse<any>;
  };
  // ...
}

What did you expect to happen?

response: OctokitResponse<any> suggests that there is a response body, but it could be of anytime. However, we know that there is no body at all.

What the problem might be

The way 204 responses are handled in generating src/generated/Endpoints.ts?

Property 'content' does not exist on type 'ReposGetContentsResponseData'

What happened?

Property 'content' does not exist on type 'ReposGetContentsResponseData'.
Property 'content' does not exist on type 'ReposGetContentsResponseDataItem[]'.

after, I've migrated my code to "@octokit/rest": "^17.6.0". The issue is visible at
https://github.com/fogfish/code-build-bot/blob/github-error/apps/webhook/lib/codebuild.ts#L39

The type definition of your library is seemed to be correct but tsc cannot see it

type ReposGetContentsResponseData =
  | {
      type: string;
      encoding?: string;
      size: number;
      name: string;
      path: string;
      content?: string;
      sha: string;
      url: string;
      git_url: string;
      html_url: string;
      download_url: string | null;
      _links: ReposGetContentsResponseDataLinks;
      target?: string;
      submodule_git_url?: string;
    }
  | Array<ReposGetContentsResponseDataItem>;

What did you expect to happen?

I would expect that Property 'content' exists on type

Incorrect type for "repos.uploadReleaseAsset"

What happened?

In octokit v16 repos.uploadReleaseAsset accepted string | object for the data prop.

In octokit v17 it only accepts a string. Running the code with as any though providing a buffer is still valid.

https://github.com/intuit/auto/blob/master/plugins/upload-assets/src/index.ts#L70

What did you expect to happen?

This endpoint should still accept a Buffer.

What the problem might be

I tried finding the place to contribute it but was unable since it is generated from somewhere else

Narrow Union of Array types activity.listReposStarredByAuthenticatedUser

I would like to import type ActivityListReposStarredByAuthenticatedUserResponseData which is one of the response types for
await octokit.activity.listReposStarredByAuthenticatedUser() rather than use any[].
response type is OctokitResponse<ActivityListReposStarredByAuthenticatedUserResponseData | ActivityListReposStarredByAuthenticatedUserResponse200Data>

Missing assignees field in SearchIssuesAndPullRequestsResponseData["items"][0]

What happened?

Incorrect type for SearchIssuesAndPullRequestsResponseData (associated with RestEndpointMethodTypes["search"]["issuesAndPullRequests"]["response"]["data"]["items"])

What did you expect to happen?

Given the following minimal reproduction:

const { Octokit } = require("@octokit/rest");

async function run() {
  const octokit = new Octokit();

  try {
    const searches =  await octokit.search.issuesAndPullRequests({
      q: "repo:test-organization-kkjeer/cliff-test+is:open"
    });
    console.dir(searches);
    debugger;
    
  } catch (e) {
    debugger;

    console.dir(e);
  }
}

run();

The response includes "assignees" field while the type (see below) does not.
image

Present buggy generated type (dist-types/generated/Endpoint.d.ts, @nodes/[email protected]):

export interface SearchIssuesAndPullRequestsResponseData {
    total_count: number;
    incomplete_results: boolean;
    items: {
        url: string;
        repository_url: string;
        labels_url: string;
        comments_url: string;
        events_url: string;
        html_url: string;
        id: number;
        node_id: string;
        number: number;
        title: string;
        user: {
            login: string;
            id: number;
            node_id: string;
            avatar_url: string;
            gravatar_id: string;
            url: string;
            html_url: string;
            followers_url: string;
            following_url: string;
            gists_url: string;
            starred_url: string;
            subscriptions_url: string;
            organizations_url: string;
            repos_url: string;
            events_url: string;
            received_events_url: string;
            type: string;
        };
        labels: {
            id: number;
            node_id: string;
            url: string;
            name: string;
            color: string;
        }[];
        state: string;
        assignee: string;
        milestone: string;
        comments: number;
        created_at: string;
        updated_at: string;
        closed_at: string;
        pull_request: {
            html_url: string;
            diff_url: string;
            patch_url: string;
        };
        body: string;
        score: number;
    }[];
}

Why is this library designed as it is?

I'm new to typescript so I apologize if I'm missing something, and there seem to be no design-overview documentation.

I don't understand why I can't just rely on the return type of e.g. ocotokit.pulls.create being automatically picked up by my editor than me having to refine it from any to type X = Endpoints["POST /repos/{owner}/{repo}/pulls"]["response"] or using GetResponseTypeFromEndpointMethod

Normally I wouldn't even have to worry about the types, and as long as I specify the right keys in the object literal that I use as the argument and I use the right properties on the returned object, I'm good to go.

I also have a less important second question: is there no parameter/argument type equivalent to GetResponseTypeFromEndpointMethod?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.