Skip to content

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

@peterbe

Description

@peterbe

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: TriageThis is being looked at and prioritizedType: BugSomething isn't working as documented

    Type

    No type

    Projects

    Status

    ✅ Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions