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

Incorrect Return Type of WorkItemTrackingApi.getWorkItem(), when runtime can return null #574

Closed
Stan-Stani opened this issue Dec 6, 2023 · 3 comments

Comments

@Stan-Stani
Copy link

Concerning WorkItemTrackingApi.getWorkItem(),

res = await this.rest.get<WorkItemTrackingInterfaces.WorkItem>(url, options);

Promise<WorkItemTrackingInterfaces.WorkItem> is the type of the resolved promise, but the description of the get method of res = await this.rest.get<WorkItemTrackingInterfaces.WorkItem>(url, options); explictly says and types it as having a result of null if the response code is 404.
https://github.com/microsoft/typed-rest-client/blob/ddca2d90a7ed441e2e49d770bb5fe5456b410c5d/lib/RestClient.ts#L53

Now this.formatResponse's return type is any but logically what it returns should be handled such that it ends up matching the return type of the resolved promise when it resolves, right? That's not happening here, when this.rest.get returns null. In that case, the promise resolves as null.

image

Is this loophole the responsibility of the consumers of this library, or should it be handled here? I ask because I'm running into errors using a consuming library (https://github.com/rfennell/AzurePipelines/tree/main/Extensions/XplatGenerateReleaseNotes) due to getWorkItem() returning null when it isn't typed as returning such.

@Stan-Stani
Copy link
Author

Ah, this post is a bit of a practical answer to my issue, I think: #568 (comment)

@DenisNikulin5
Copy link
Contributor

Hi @Stan-Stani thanks for reporting! We are working on more prioritized issues at the moment, but will get back to this one soon.

Copy link

github-actions bot commented Mar 6, 2024

This issue has had no activity in 90 days. Please comment if it is not actually stale

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants