diff --git a/api_guard/dist/types/ajax/index.d.ts b/api_guard/dist/types/ajax/index.d.ts index 3f0a494eb4..bda26abbd5 100644 --- a/api_guard/dist/types/ajax/index.d.ts +++ b/api_guard/dist/types/ajax/index.d.ts @@ -56,13 +56,13 @@ export declare class AjaxResponse { 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 { diff --git a/src/internal/ajax/AjaxResponse.ts b/src/internal/ajax/AjaxResponse.ts index 082d359d99..c9ca915bea 100644 --- a/src/internal/ajax/AjaxResponse.ts +++ b/src/internal/ajax/AjaxResponse.ts @@ -1,4 +1,4 @@ -import { AjaxRequest } from './types'; +import { AjaxRequest, AjaxResponseType } from './types'; import { getXHRResponse } from './getXHRResponse'; /** @@ -90,7 +90,7 @@ export class AjaxResponse { * `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; diff --git a/src/internal/ajax/ajax.ts b/src/internal/ajax/ajax.ts index 72ee5fbc22..e54e2cbd4c 100644 --- a/src/internal/ajax/ajax.ts +++ b/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'; @@ -414,7 +414,7 @@ export function fromAjax(config: AjaxConfig): Observable> { * @param event the actual event object. */ const createResponse = (direction: AjaxDirection, event: ProgressEvent) => - new AjaxResponse(event, xhr, _request, `${direction}_${event.type}`); + new AjaxResponse(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 diff --git a/src/internal/ajax/types.ts b/src/internal/ajax/types.ts index 2a2660e491..0d932e300e 100644 --- a/src/internal/ajax/types.ts +++ b/src/internal/ajax/types.ts @@ -7,6 +7,10 @@ import { PartialObserver } from '../types'; */ export type AjaxDirection = 'upload' | 'download'; +export type ProgressEventType = 'loadstart' | 'progress' | 'load'; + +export type AjaxResponseType = `${AjaxDirection}_${ProgressEventType}`; + /** * The object containing values RxJS used to make the HTTP request. *