Skip to content

Create a IZosFilesTypedResponse to offer stronger type inference for returned items #2421

Open
@traeok

Description

Is your feature or enhancement request related to a problem or limitation? Please describe

When using z/OS File APIs, the expected properties in apiResponse are unclear. Since apiResponse is typed as any, this has also allowed inconsistencies to appear in the structure for apiResponse, even though we populate this property ourselves - see #2410

Describe your enhancement idea

By offering a IZosFilesTypedResponse, we can strongly type the apiResponse property to provide TypeScript inference for developers that process these responses.

Example:

export interface IApiResponseWithItems<T> {
    items: T[];
    // ...any remaining properties in `apiResponse` if applicable
    // support any responses that have an `items` property of type `T[]`
    [key: string]: any;
}

export interface IZosFilesTypedResponse<T> implements IZosFilesResponse {
    apiResponse?: IApiResponseWithItems<T>;
}

Describe alternatives you've considered

Users can try to interpret the response by printing it and keeping track of the keys that are returned, referencing existing code, or looking at z/OSMF API documentation. However, this opens up room for mistakes as apiResponse is any, so any property access is considered valid by TypeScript until executed at runtime:

// Invalid property, but this will compile due to the use of `any`
apiResponse.banana

Activity

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

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestpriority-lowLegit issue but cosmetic or nice-to-havev4Prospective changes for v4

    Type

    No type

    Projects

    • Status

      Low Priority

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions