Skip to content

Commit e572d2e

Browse files
authored
chore: deprecate error ctors (#6277)
* chore: add deprecations to error ctors * test: add test for error ctor deprecations * chore: remove old dtslint comment - TS 2.8 lol
1 parent 34e4bde commit e572d2e

File tree

10 files changed

+75
-13
lines changed

10 files changed

+75
-13
lines changed

spec-dtslint/errors-spec.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { AjaxError, AjaxTimeoutError } from 'rxjs/ajax';
2+
import {
3+
ArgumentOutOfRangeError,
4+
EmptyError,
5+
NotFoundError,
6+
ObjectUnsubscribedError,
7+
SequenceError,
8+
TimeoutError,
9+
UnsubscriptionError
10+
} from 'rxjs';
11+
12+
it('should deprecate error construction', () => {
13+
let error: Error;
14+
error = new AjaxError('message', null!, null!); // $ExpectDeprecation
15+
error = new ArgumentOutOfRangeError(); // $ExpectDeprecation
16+
error = new EmptyError(); // $ExpectDeprecation
17+
error = new NotFoundError('message'); // $ExpectDeprecation
18+
error = new ObjectUnsubscribedError(); // $ExpectDeprecation
19+
error = new SequenceError('message'); // $ExpectDeprecation
20+
error = new TimeoutError(); // $ExpectDeprecation
21+
error = new UnsubscriptionError([]); // $ExpectDeprecation
22+
});
23+
24+
it('should not deprecate instanceof use', () => {
25+
const error = new Error('message');
26+
let b: boolean;
27+
b = error instanceof AjaxError; // $ExpectNoDeprecation
28+
b = error instanceof ArgumentOutOfRangeError; // $ExpectNoDeprecation
29+
b = error instanceof EmptyError; // $ExpectNoDeprecation
30+
b = error instanceof NotFoundError; // $ExpectNoDeprecation
31+
b = error instanceof ObjectUnsubscribedError; // $ExpectNoDeprecation
32+
b = error instanceof SequenceError; // $ExpectNoDeprecation
33+
b = error instanceof TimeoutError; // $ExpectNoDeprecation
34+
b = error instanceof UnsubscriptionError; // $ExpectNoDeprecation
35+
});

spec-dtslint/index.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
// TypeScript Version: 2.8

src/internal/ajax/errors.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ export interface AjaxError extends Error {
3939

4040
export interface AjaxErrorCtor {
4141
/**
42-
* Internal use only. Do not manually create instances of this type.
42+
* @deprecated Internal implementation detail. Do not construct error instances.
43+
* Cannot be tagged as internal: https://github.com/ReactiveX/rxjs/issues/6269
4344
*/
4445
new (message: string, xhr: XMLHttpRequest, request: AjaxRequest): AjaxError;
4546
}
@@ -78,7 +79,8 @@ export interface AjaxTimeoutError extends AjaxError {}
7879

7980
export interface AjaxTimeoutErrorCtor {
8081
/**
81-
* Internal use only. Do not manually create instances of this type.
82+
* @deprecated Internal implementation detail. Do not construct error instances.
83+
* Cannot be tagged as internal: https://github.com/ReactiveX/rxjs/issues/6269
8284
*/
8385
new (xhr: XMLHttpRequest, request: AjaxRequest): AjaxTimeoutError;
8486
}

src/internal/operators/timeout.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ export interface TimeoutError<T = unknown, M = unknown> extends Error {
6767

6868
export interface TimeoutErrorCtor {
6969
/**
70-
* Internal use only. DO NOT create new instances of TimeoutError directly.
71-
* This type is exported for the purpose of `instanceof` checks.
70+
* @deprecated Internal implementation detail. Do not construct error instances.
71+
* Cannot be tagged as internal: https://github.com/ReactiveX/rxjs/issues/6269
7272
*/
7373
new <T = unknown, M = unknown>(info?: TimeoutInfo<T, M>): TimeoutError<T, M>;
7474
}

src/internal/util/ArgumentOutOfRangeError.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import { createErrorClass } from './createErrorClass';
33
export interface ArgumentOutOfRangeError extends Error {}
44

55
export interface ArgumentOutOfRangeErrorCtor {
6+
/**
7+
* @deprecated Internal implementation detail. Do not construct error instances.
8+
* Cannot be tagged as internal: https://github.com/ReactiveX/rxjs/issues/6269
9+
*/
610
new (): ArgumentOutOfRangeError;
711
}
812

src/internal/util/EmptyError.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { createErrorClass } from './createErrorClass';
22

3-
export interface EmptyError extends Error {
4-
}
3+
export interface EmptyError extends Error {}
54

65
export interface EmptyErrorCtor {
7-
new(): EmptyError;
6+
/**
7+
* @deprecated Internal implementation detail. Do not construct error instances.
8+
* Cannot be tagged as internal: https://github.com/ReactiveX/rxjs/issues/6269
9+
*/
10+
new (): EmptyError;
811
}
912

1013
/**
@@ -17,8 +20,11 @@ export interface EmptyErrorCtor {
1720
*
1821
* @class EmptyError
1922
*/
20-
export const EmptyError: EmptyErrorCtor = createErrorClass((_super) => function EmptyErrorImpl(this: any) {
21-
_super(this);
22-
this.name = 'EmptyError';
23-
this.message = 'no elements in sequence';
24-
});
23+
export const EmptyError: EmptyErrorCtor = createErrorClass(
24+
(_super) =>
25+
function EmptyErrorImpl(this: any) {
26+
_super(this);
27+
this.name = 'EmptyError';
28+
this.message = 'no elements in sequence';
29+
}
30+
);

src/internal/util/NotFoundError.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import { createErrorClass } from './createErrorClass';
33
export interface NotFoundError extends Error {}
44

55
export interface NotFoundErrorCtor {
6+
/**
7+
* @deprecated Internal implementation detail. Do not construct error instances.
8+
* Cannot be tagged as internal: https://github.com/ReactiveX/rxjs/issues/6269
9+
*/
610
new (message: string): NotFoundError;
711
}
812

src/internal/util/ObjectUnsubscribedError.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import { createErrorClass } from './createErrorClass';
33
export interface ObjectUnsubscribedError extends Error {}
44

55
export interface ObjectUnsubscribedErrorCtor {
6+
/**
7+
* @deprecated Internal implementation detail. Do not construct error instances.
8+
* Cannot be tagged as internal: https://github.com/ReactiveX/rxjs/issues/6269
9+
*/
610
new (): ObjectUnsubscribedError;
711
}
812

src/internal/util/SequenceError.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import { createErrorClass } from './createErrorClass';
33
export interface SequenceError extends Error {}
44

55
export interface SequenceErrorCtor {
6+
/**
7+
* @deprecated Internal implementation detail. Do not construct error instances.
8+
* Cannot be tagged as internal: https://github.com/ReactiveX/rxjs/issues/6269
9+
*/
610
new (message: string): SequenceError;
711
}
812

src/internal/util/UnsubscriptionError.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ export interface UnsubscriptionError extends Error {
55
}
66

77
export interface UnsubscriptionErrorCtor {
8+
/**
9+
* @deprecated Internal implementation detail. Do not construct error instances.
10+
* Cannot be tagged as internal: https://github.com/ReactiveX/rxjs/issues/6269
11+
*/
812
new (errors: any[]): UnsubscriptionError;
913
}
1014

0 commit comments

Comments
 (0)