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

chore: deprecate error ctors #6277

Merged
merged 3 commits into from Apr 28, 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
35 changes: 35 additions & 0 deletions spec-dtslint/errors-spec.ts
@@ -0,0 +1,35 @@
import { AjaxError, AjaxTimeoutError } from 'rxjs/ajax';
import {
ArgumentOutOfRangeError,
EmptyError,
NotFoundError,
ObjectUnsubscribedError,
SequenceError,
TimeoutError,
UnsubscriptionError
} from 'rxjs';

it('should deprecate error construction', () => {
let error: Error;
error = new AjaxError('message', null!, null!); // $ExpectDeprecation
error = new ArgumentOutOfRangeError(); // $ExpectDeprecation
error = new EmptyError(); // $ExpectDeprecation
error = new NotFoundError('message'); // $ExpectDeprecation
error = new ObjectUnsubscribedError(); // $ExpectDeprecation
error = new SequenceError('message'); // $ExpectDeprecation
error = new TimeoutError(); // $ExpectDeprecation
error = new UnsubscriptionError([]); // $ExpectDeprecation
});

it('should not deprecate instanceof use', () => {
const error = new Error('message');
let b: boolean;
b = error instanceof AjaxError; // $ExpectNoDeprecation
b = error instanceof ArgumentOutOfRangeError; // $ExpectNoDeprecation
b = error instanceof EmptyError; // $ExpectNoDeprecation
b = error instanceof NotFoundError; // $ExpectNoDeprecation
b = error instanceof ObjectUnsubscribedError; // $ExpectNoDeprecation
b = error instanceof SequenceError; // $ExpectNoDeprecation
b = error instanceof TimeoutError; // $ExpectNoDeprecation
b = error instanceof UnsubscriptionError; // $ExpectNoDeprecation
});
1 change: 0 additions & 1 deletion spec-dtslint/index.d.ts
@@ -1 +0,0 @@
// TypeScript Version: 2.8
6 changes: 4 additions & 2 deletions src/internal/ajax/errors.ts
Expand Up @@ -39,7 +39,8 @@ export interface AjaxError extends Error {

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

export interface AjaxTimeoutErrorCtor {
/**
* Internal use only. Do not manually create instances of this type.
* @deprecated Internal implementation detail. Do not construct error instances.
* Cannot be tagged as internal: https://github.com/ReactiveX/rxjs/issues/6269
*/
new (xhr: XMLHttpRequest, request: AjaxRequest): AjaxTimeoutError;
}
Expand Down
4 changes: 2 additions & 2 deletions src/internal/operators/timeout.ts
Expand Up @@ -67,8 +67,8 @@ export interface TimeoutError<T = unknown, M = unknown> extends Error {

export interface TimeoutErrorCtor {
/**
* Internal use only. DO NOT create new instances of TimeoutError directly.
* This type is exported for the purpose of `instanceof` checks.
* @deprecated Internal implementation detail. Do not construct error instances.
* Cannot be tagged as internal: https://github.com/ReactiveX/rxjs/issues/6269
*/
new <T = unknown, M = unknown>(info?: TimeoutInfo<T, M>): TimeoutError<T, M>;
}
Expand Down
4 changes: 4 additions & 0 deletions src/internal/util/ArgumentOutOfRangeError.ts
Expand Up @@ -3,6 +3,10 @@ import { createErrorClass } from './createErrorClass';
export interface ArgumentOutOfRangeError extends Error {}

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

Expand Down
22 changes: 14 additions & 8 deletions src/internal/util/EmptyError.ts
@@ -1,10 +1,13 @@
import { createErrorClass } from './createErrorClass';

export interface EmptyError extends Error {
}
export interface EmptyError extends Error {}

export interface EmptyErrorCtor {
new(): EmptyError;
/**
* @deprecated Internal implementation detail. Do not construct error instances.
* Cannot be tagged as internal: https://github.com/ReactiveX/rxjs/issues/6269
*/
new (): EmptyError;
}

/**
Expand All @@ -17,8 +20,11 @@ export interface EmptyErrorCtor {
*
* @class EmptyError
*/
export const EmptyError: EmptyErrorCtor = createErrorClass((_super) => function EmptyErrorImpl(this: any) {
_super(this);
this.name = 'EmptyError';
this.message = 'no elements in sequence';
});
export const EmptyError: EmptyErrorCtor = createErrorClass(
(_super) =>
function EmptyErrorImpl(this: any) {
_super(this);
this.name = 'EmptyError';
this.message = 'no elements in sequence';
}
);
4 changes: 4 additions & 0 deletions src/internal/util/NotFoundError.ts
Expand Up @@ -3,6 +3,10 @@ import { createErrorClass } from './createErrorClass';
export interface NotFoundError extends Error {}

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

Expand Down
4 changes: 4 additions & 0 deletions src/internal/util/ObjectUnsubscribedError.ts
Expand Up @@ -3,6 +3,10 @@ import { createErrorClass } from './createErrorClass';
export interface ObjectUnsubscribedError extends Error {}

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

Expand Down
4 changes: 4 additions & 0 deletions src/internal/util/SequenceError.ts
Expand Up @@ -3,6 +3,10 @@ import { createErrorClass } from './createErrorClass';
export interface SequenceError extends Error {}

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

Expand Down
4 changes: 4 additions & 0 deletions src/internal/util/UnsubscriptionError.ts
Expand Up @@ -5,6 +5,10 @@ export interface UnsubscriptionError extends Error {
}

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

Expand Down