Skip to content

Commit 839e192

Browse files
authored
feat(AjaxResponse): add stricter type (AjaxResponseType) (#6279)
1 parent f43c728 commit 839e192

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

api_guard/dist/types/ajax/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ export declare class AjaxResponse<T> {
5656
readonly responseType: XMLHttpRequestResponseType;
5757
readonly status: number;
5858
readonly total: number;
59-
readonly type: string;
59+
readonly type: AjaxResponseType;
6060
readonly xhr: XMLHttpRequest;
6161
constructor(
6262
originalEvent: ProgressEvent,
6363
xhr: XMLHttpRequest,
6464
request: AjaxRequest,
65-
type?: string);
65+
type?: AjaxResponseType);
6666
}
6767

6868
export interface AjaxTimeoutError extends AjaxError {

src/internal/ajax/AjaxResponse.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AjaxRequest } from './types';
1+
import { AjaxRequest, AjaxResponseType } from './types';
22
import { getXHRResponse } from './getXHRResponse';
33

44
/**
@@ -90,7 +90,7 @@ export class AjaxResponse<T> {
9090
* `download_load` is the type of event when download has finished and the
9191
* response is available.
9292
*/
93-
public readonly type: string = 'download_load'
93+
public readonly type: AjaxResponseType = 'download_load'
9494
) {
9595
const { status, responseType } = xhr;
9696
this.status = status ?? 0;

src/internal/ajax/ajax.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { map } from '../operators/map';
22
import { Observable } from '../Observable';
3-
import { AjaxConfig, AjaxRequest, AjaxDirection } from './types';
3+
import { AjaxConfig, AjaxRequest, AjaxDirection, ProgressEventType } from './types';
44
import { AjaxResponse } from './AjaxResponse';
55
import { AjaxTimeoutError, AjaxError } from './errors';
66

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

419419
/**
420420
* Wires up an event handler that emits a Response object to the consumer, used for

src/internal/ajax/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import { PartialObserver } from '../types';
77
*/
88
export type AjaxDirection = 'upload' | 'download';
99

10+
export type ProgressEventType = 'loadstart' | 'progress' | 'load';
11+
12+
export type AjaxResponseType = `${AjaxDirection}_${ProgressEventType}`;
13+
1014
/**
1115
* The object containing values RxJS used to make the HTTP request.
1216
*

0 commit comments

Comments
 (0)