Skip to content

Derive getUserOctokit return type from Octokit option #262

@inga-lovinde

Description

@inga-lovinde

What happened?

import { Octokit, OAuthApp } from 'octokit'

const app = new OAuthApp({
  clientType: 'oauth-app',
  clientId: 'fakeClientId',
  clientSecret: 'fakeClientSecret',
})

const octokit: Octokit = await app.getUserOctokit({ code: 'fakeCode' })

causes a type error in the last line, because the unwrapped return value of app.getUserOctokit is not assignable to the constant of type Octokit.

What did you expect to happen?

No type errors.

What the problem might be

app.getUserOctokit returns a promise of an instance type of Octokit option.

However, app.getUserOctokit is declared as returning Promise<OctokitInstance>, where OctokitInstance is hardcoded to be an instance type of OAuthTypeOctokit, regardless of the options passed to OAuthApp constructor.

It should probably be declared as returning Promise<OctokitTypeFromOptions<TOptions>> instead.

A similar issue (but about octokit field instead of getUserOctokit method) is #212.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: Up for grabsIssues that are ready to be worked on by anyoneType: BugSomething isn't working as documentedreleasedtypescriptRelevant to TypeScript users only

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions