jdalrymple / gitbeaker

🦊🧪 A comprehensive and typed Gitlab SDK for Node.js, Browsers, Deno and CLI
Other
1.5k stars 283 forks source link

[Typescript] Type AllMergeRequestsOptions has "Any" and "None" missing for "assigneeId" #3562

Closed KoenBrouwer closed 3 months ago

KoenBrouwer commented 3 months ago

Description

I noticed that Typescript does not agree with the following piece of code:

import { Gitlab } from "@gitbeaker/rest";

const client = new GitLab();
const mergeRequests = await client.MergeRequests.all({
    projectId: "abcd1234",
    wip: "no",
    // @ts-expect-error assigneeId can only be a number, but "Any" and "None" are valid options according to the GitLab REST API docs.
    assigneeId: "None", // <-- 💥
});

console.log(mergeRequests); // An array of merge requests with no assignee 

Expected behaviour

Typescript should not complain about assigneeId being "Any" or "None".

Actual behaviour

Typescript complains with the following error:

error TS2769: No overload matches this call.
  Overload 1 of 2, '(options: OneOrNoneOf<{ projectId: string | number; groupId: string | number; }> & BasePaginationRequestOptions<"offset"> & OffsetPaginationRequestOptions & AllMergeRequestsOptions & { ...; }): Promise<...>', gave the following error.
    Type 'string' is not assignable to type 'number'.
  Overload 2 of 2, '(options?: (OneOrNoneOf<{ projectId: string | number; groupId: string | number; }> & BasePaginationRequestOptions<"offset"> & OffsetPaginationRequestOptions & ... 4 more ... & { ...; }) | undefined): Promise<...>', gave the following error.
    Type 'string' is not assignable to type 'number'.

             assigneeId: "None",

In summary, Typescript doesn't agree with assigneeId not being a number, whereas as per the GitLab REST API documentation, assigneeId must be either a number or Any or None.

Possible fixes

Allow Any and None for assigneeId on line 196 of /packages/core/src/resources/MergeRequests.ts.

https://github.com/jdalrymple/gitbeaker/blob/1431e845353d73026878ab554a0deb379d08ec68/packages/core/src/resources/MergeRequests.ts#L192-L200

https://github.com/KoenBrouwer/gitbeaker/blob/d7f3d641f9b8db192c1c20982e440586ca4bdb70/packages/core/src/resources/MergeRequests.ts#L192-L200

Checklist

jdalrymple commented 3 months ago

:rocket: Issue was released in 40.0.2 :rocket: