Skip to content

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

Closed

Description

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.

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

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions