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

[BUG]: TypeScript error when using with @octokit/rest #528

Closed
1 task done
peterbe opened this issue Mar 18, 2024 · 6 comments
Closed
1 task done

[BUG]: TypeScript error when using with @octokit/rest #528

peterbe opened this issue Mar 18, 2024 · 6 comments
Labels
Status: Triage This is being looked at and prioritized Type: Bug Something isn't working as documented

Comments

@peterbe
Copy link

peterbe commented Mar 18, 2024

What happened?

Steps to reproduce:

cd /tmp
mkdir retry-ts-type
cd retry-ts-type
npm init -y && npm install -D typescript && npm install @octokit/rest @octokit/plugin-retry

Create code.ts

import { Octokit } from "@octokit/rest"
import { retry } from "@octokit/plugin-retry"
const MyOctokit = Octokit.plugin(retry);

Init typescript

tsc --init

Run tsc linter:

❯ tsc --noEmit
code.ts:3:34 - error TS2345: Argument of type 'typeof retry' is not assignable to parameter of type 'OctokitPlugin'.
  Types of parameters 'octokit' and 'octokit' are incompatible.
    Type 'import("/private/tmp/retry-ts-type/node_modules/@octokit/rest/node_modules/@octokit/core/dist-types/index").Octokit' is not assignable to type 'import("/private/tmp/retry-ts-type/node_modules/@octokit/core/dist-types/index").Octokit'.
      The types of 'hook.before' are incompatible between these types.
        Type '<Name extends keyof Hooks>(name: Name, beforeHook: BeforeHook<GetType<Hooks[Name], "Options", "O">>) => void' is not assignable to type '<Name extends keyof Hooks>(name: Name, beforeHook: BeforeHook<GetType<Hooks[Name], "Options">>) => void'.
          Types of parameters 'beforeHook' and 'beforeHook' are incompatible.
            Types of parameters 'options' and 'options' are incompatible.
              Type 'GetType<Hooks[Name], "Options", "O">' is not assignable to type 'GetType<Hooks[Name], "Options">'.
                Type 'Hooks[Name][keyof Hooks[Name] & "Options"] | ("O" extends keyof Hooks[Name] ? Hooks[Name][keyof Hooks[Name] & "O"] : any)' is not assignable to type 'GetType<Hooks[Name], "Options">'.
                  Type 'Hooks[Name][keyof Hooks[Name] & "Options"]' is not assignable to type 'GetType<Hooks[Name], "Options">'.
                    Type 'Hooks[Name]["Options"]' is not assignable to type 'GetType<Hooks[Name], "Options">'.

3 const MyOctokit = Octokit.plugin(retry);
                                   ~~~~~


Found 1 error in code.ts:3

In VS Code:

VS code typrscript error

Versions

❯ cat package.json
{
  "name": "retry-ts-type",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "typescript": "5.4.2"
  },
  "dependencies": {
    "@octokit/plugin-retry": "7.0.3",
    "@octokit/rest": "20.0.2"
  }
}

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@peterbe peterbe added Status: Triage This is being looked at and prioritized Type: Bug Something isn't working as documented labels Mar 18, 2024
Copy link

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

@wolfy1339
Copy link
Member

You cannot mix those versions.
@octokit/plugin-retry has swtiched to ESM and updated dependencies, thus is incompatible.

Please read the changelog before trying to use the module

@peterbe
Copy link
Author

peterbe commented Mar 18, 2024

NOTE! I don't know if this is a types bug with @octokit/plugin-retry or if it's with @octokit/rest!
If you make this edit:

-import { Octokit } from "@octokit/rest";
+import { Octokit } from "@octokit/core";
import { retry } from "@octokit/plugin-retry";
const MyOctokit = Octokit.plugin(retry);

Then:

❯ tsc --noEmit

But I want to use @octokit/rest because it has other useful types. For example:

import { Octokit } from "@octokit/rest";
import { retry } from "@octokit/plugin-retry";
const MyOctokit = Octokit.plugin(retry);

const octokit = new MyOctokit();

octokit.issues.listComments({
  owner: "octokit",
  repo: "plugin-retry.js",
  issue_number: 528,
});

It's one or the other:

Using @octokit/rest
VS Code

Using @octokit/core
VS Code snippet

@wolfy1339
Copy link
Member

Simply downgrade @octokit/plugin-retry to the previous major version

@peterbe
Copy link
Author

peterbe commented Mar 18, 2024

You cannot mix those versions. @octokit/plugin-retry has swtiched to ESM and updated dependencies, thus is incompatible.

Please read the changelog before trying to use the module

Ah. So of the 3 used @octokit/* plugins, not all have switched to ESM?

@wolfy1339
Copy link
Member

Exactly. There is currently a snag that is blocking the update.
octokit/rest.js#413
octokit/auth-app.js#580

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Triage This is being looked at and prioritized Type: Bug Something isn't working as documented
Projects
Archived in project
Development

No branches or pull requests

2 participants