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

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

Closed
2 tasks done
ghost opened this issue Aug 30, 2021 · 7 comments · Fixed by #105
Closed
2 tasks done
Labels
Type: Bug Something isn't working as documented typescript

Comments

@ghost
Copy link

ghost commented Aug 30, 2021

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; }[]

@ghost ghost added the Type: Bug Something isn't working as documented label Aug 30, 2021
@gr2m
Copy link
Contributor

gr2m commented Aug 30, 2021

Thanks @sonnen-athene I was able to reproduce the problem using @octokit/openapi-types: TypeScript playground link

image

RequestBodyParameters["labels"] should be a union, not an intersection.

this might either be a problem with GitHub's OpenAPI spec that we use to generate the types for the endpoints, or the generated types in https://github.com/octokit/openapi-types.ts.

I won't be able to look into this today myself, but will get to it eventually. Can you check the OpenAPI spec? I gut feeling is that there is a allOf where there should be a anyOf in the spec for this operation

@ghost
Copy link
Author

ghost commented Aug 30, 2021

Thanks for the quick turn around. I'll give those a look and see what I can find out.

@ghost
Copy link
Author

ghost commented Aug 30, 2021

Looks like this is already captured in this issue and isn't caused by this library. Because of that I'll go ahead and close.

@ghost ghost closed this as completed Aug 30, 2021
@gr2m
Copy link
Contributor

gr2m commented Aug 30, 2021

perfect, thank you so much for tracking that down. I'm sorry I forgot about that one

@zzTopperbot

This comment has been minimized.

@gr2m

This comment has been minimized.

@github-actions
Copy link
Contributor

🎉 This issue has been resolved in version 18.10.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working as documented typescript
Projects
None yet
2 participants