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

feat(AjaxResponse): add stricter type (AjaxResponseType) #6279

Merged
merged 1 commit into from Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions api_guard/dist/types/ajax/index.d.ts
Expand Up @@ -56,13 +56,13 @@ export declare class AjaxResponse<T> {
readonly responseType: XMLHttpRequestResponseType;
readonly status: number;
readonly total: number;
readonly type: string;
readonly type: AjaxResponseType;
readonly xhr: XMLHttpRequest;
constructor(
originalEvent: ProgressEvent,
xhr: XMLHttpRequest,
request: AjaxRequest,
type?: string);
type?: AjaxResponseType);
}

export interface AjaxTimeoutError extends AjaxError {
Expand Down
4 changes: 2 additions & 2 deletions src/internal/ajax/AjaxResponse.ts
@@ -1,4 +1,4 @@
import { AjaxRequest } from './types';
import { AjaxRequest, AjaxResponseType } from './types';
import { getXHRResponse } from './getXHRResponse';

/**
Expand Down Expand Up @@ -90,7 +90,7 @@ export class AjaxResponse<T> {
* `download_load` is the type of event when download has finished and the
* response is available.
*/
public readonly type: string = 'download_load'
public readonly type: AjaxResponseType = 'download_load'
) {
const { status, responseType } = xhr;
this.status = status ?? 0;
Expand Down
4 changes: 2 additions & 2 deletions src/internal/ajax/ajax.ts
@@ -1,6 +1,6 @@
import { map } from '../operators/map';
import { Observable } from '../Observable';
import { AjaxConfig, AjaxRequest, AjaxDirection } from './types';
import { AjaxConfig, AjaxRequest, AjaxDirection, ProgressEventType } from './types';
import { AjaxResponse } from './AjaxResponse';
import { AjaxTimeoutError, AjaxError } from './errors';

Expand Down Expand Up @@ -414,7 +414,7 @@ export function fromAjax<T>(config: AjaxConfig): Observable<AjaxResponse<T>> {
* @param event the actual event object.
*/
const createResponse = (direction: AjaxDirection, event: ProgressEvent) =>
new AjaxResponse<T>(event, xhr, _request, `${direction}_${event.type}`);
new AjaxResponse<T>(event, xhr, _request, `${direction}_${event.type as ProgressEventType}` as const);

/**
* Wires up an event handler that emits a Response object to the consumer, used for
Expand Down
4 changes: 4 additions & 0 deletions src/internal/ajax/types.ts
Expand Up @@ -7,6 +7,10 @@ import { PartialObserver } from '../types';
*/
export type AjaxDirection = 'upload' | 'download';

export type ProgressEventType = 'loadstart' | 'progress' | 'load';

export type AjaxResponseType = `${AjaxDirection}_${ProgressEventType}`;
OliverJAsh marked this conversation as resolved.
Show resolved Hide resolved

/**
* The object containing values RxJS used to make the HTTP request.
*
Expand Down