Skip to content

TypeScript signature of issues.setLabels does not allow correct type of labels attribute. #104

@ghost

Description

Checklist

Environment

  • Node.js

Versions

├── @octokit/auth-app@3.6.0
├── @octokit/rest@18.9.1

What happened?

The params object type for rest.issues.setLabels requires the labels attribute to be of type string[] & { name: string; }[] I have not found a value that allows this type signature to be satisfied, and I think it is incorrect.

Minimal test case to reproduce the problem

export const setIssueLabels = async (
  context: Context,
  labels: string[]
): Promise<void> => {
  await context.client.rest.issues.setLabels({
    issue_number: context.issue.number,
    owner: context.repo.owner,
    repo: context.repo.repo,
    labels: labels,
  });
};

Causes the following TypeScript error:

Type 'string[]' is not assignable to type 'string[] & { name: string; }[]'.
  Type 'string[]' is not assignable to type '{ name: string; }[]'.
    Type 'string' is not assignable to type '{ name: string; }'

The error also occurs when attempting to pass in an array of { name: string }

I know that using a string[] is valid, the above code works, it just requires casting the labels to any.

What did you expect to happen?

string[] to be an allowed type of labels attribute

What the problem might be

The type of labels attribute should be string[] | { name: string; }[]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions