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

fix: use unknown type for errors #5084

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions spec-dtslint/Observable-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,12 @@ describe('pipe', () => {
const customOperator = () => <T>(a: Observable<T>) => a;
const o = of('foo').pipe(customOperator()); // $ExpectType Observable<string>
});

it('should not make assumptions about the error type', () => {
of('foo').subscribe({
error: error => {
error.name; // $ExpectError
}
});
});
});
8 changes: 6 additions & 2 deletions spec/observables/dom/ajax-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -974,8 +974,12 @@ describe('ajax', () => {
ajax(ajaxRequest)
.subscribe({
error(err) {
expect(err.name).to.equal('AjaxTimeoutError');
done();
if (err instanceof AjaxTimeoutError) {
expect(err.name).to.equal('AjaxTimeoutError');
done();
} else {
throw new Error('expected an AjaxTimeoutError');
}
}
});

Expand Down
8 changes: 4 additions & 4 deletions src/internal/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,21 @@ export type InteropObservable<T> = { [Symbol.observable]: () => Subscribable<T>;
export interface NextObserver<T> {
closed?: boolean;
next: (value: T) => void;
error?: (err: any) => void;
error?: (err: unknown) => void;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There might be other places to update this.

complete?: () => void;
}

export interface ErrorObserver<T> {
closed?: boolean;
next?: (value: T) => void;
error: (err: any) => void;
error: (err: unknown) => void;
complete?: () => void;
}

export interface CompletionObserver<T> {
closed?: boolean;
next?: (value: T) => void;
error?: (err: any) => void;
error?: (err: unknown) => void;
complete: () => void;
}

Expand All @@ -84,7 +84,7 @@ export type PartialObserver<T> = NextObserver<T> | ErrorObserver<T> | Completion
export interface Observer<T> {
closed?: boolean;
next: (value: T) => void;
error: (err: any) => void;
error: (err: unknown) => void;
complete: () => void;
}

Expand Down