0

I have the following reasonably straight-forward code:

export async function getAllRepos({
  token,
}: {
  token: string;
}): Promise<ReposListForOrgResponseData> {
  const octokit = buildOctokit(token);

  const repos = await octokit.paginate(octokit.repos.listForOrg, {
    org: OWNER,
  });

  return repos;
}

Typescript does not like this and gives me the error:

src/lib/github.ts:130:3 - error TS2322: Type '{ id: number; node_id: string; name: string; full_name: string; owner: { name?: string | null | undefined; email?: string | null | undefined; login: string; id: number; node_id: string; avatar_url: string; ... 14 more ...; starred_at?: string | undefined; }; ... 79 more ...; allow_forking?: boolean | undefined; }[]' is not assignable to type 'ReposListForOrgResponseData'.
  Type '{ id: number; node_id: string; name: string; full_name: string; owner: { name?: string | null | undefined; email?: string | null | undefined; login: string; id: number; node_id: string; avatar_url: string; ... 14 more ...; starred_at?: string | undefined; }; ... 79 more ...; allow_forking?: boolean | undefined; }' is not assignable to type '{ id: number; node_id: string; name: string; full_name: string; owner: { login: string; id: number; node_id: string; avatar_url: string; gravatar_id: string; url: string; html_url: string; followers_url: string; ... 9 more ...; site_admin: boolean; }; ... 73 more ...; license: { ...; }; }'.
    The types of 'owner.gravatar_id' are incompatible between these types.
      Type 'string | null' is not assignable to type 'string'.
        Type 'null' is not assignable to type 'string'.

130   return repos;
      ~~~~~~

I'm not sure why the types don't match up but it's impossible to figure this out following the definitions or looking at the octokit website. @octokit/rest and @octokit/types don't seem to have anything to do with each other.

Octokit/rest is at 18.12.0 and the types are at 5.5.0.

Alper
  • 3,424
  • 4
  • 39
  • 45
  • What is the definition of `ReposListForOrgResponseData`? Where does it come from? I can't find anything on the internet other than your question referencing that. – Sergiu Paraschiv Aug 25 '23 at 10:46
  • 1
    Looking at the package-lock.json file on the 18.x branch (https://raw.githubusercontent.com/octokit/rest.js/18.x/package-lock.json) I can see that all it's dependencies require @oktokit/types ^6.x, which means you are using an incompatible version. That's where the type mismatch is probably coming from. – Sergiu Paraschiv Aug 25 '23 at 11:09
  • I too had a hard time finding it in the code but it seems it's provided by the octokit types. – Alper Aug 25 '23 at 11:24

0 Answers0