Skip to content

Commit 02a9098

Browse files
types(config): add GlobalConfig interface (#6247)
* chore(config): add GlobalConfig interface * chore: update api_guardian * chore: move GlobalConfig declaration to config.ts * chore: update api_guardian * chore: remove excessive types from config properties * chore(config): remove extra empty lines
1 parent 839e192 commit 02a9098

File tree

3 files changed

+33
-18
lines changed

3 files changed

+33
-18
lines changed

api_guard/dist/types/index.d.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,7 @@ export interface CompletionObserver<T> {
6969
export declare function concat<T extends readonly unknown[]>(...inputs: [...ObservableInputTuple<T>]): Observable<T[number]>;
7070
export declare function concat<T extends readonly unknown[]>(...inputsAndScheduler: [...ObservableInputTuple<T>, SchedulerLike]): Observable<T[number]>;
7171

72-
export declare const config: {
73-
onUnhandledError: ((err: any) => void) | null;
74-
onStoppedNotification: ((notification: ObservableNotification<any>, subscriber: Subscriber<any>) => void) | null;
75-
Promise: PromiseConstructorLike | undefined;
76-
useDeprecatedSynchronousErrorHandling: boolean;
77-
useDeprecatedNextContext: boolean;
78-
};
72+
export declare const config: GlobalConfig;
7973

8074
export declare function connectable<T>(source: ObservableInput<T>, config?: ConnectableConfig<T>): ConnectableObservableLike<T>;
8175

@@ -162,6 +156,14 @@ export declare function generate<S>(initialState: S, condition: ConditionFunc<S>
162156
export declare function generate<S>(options: GenerateBaseOptions<S>): Observable<S>;
163157
export declare function generate<T, S>(options: GenerateOptions<T, S>): Observable<T>;
164158

159+
export interface GlobalConfig {
160+
Promise?: PromiseConstructorLike;
161+
onStoppedNotification: ((notification: ObservableNotification<any>, subscriber: Subscriber<any>) => void) | null;
162+
onUnhandledError: ((err: any) => void) | null;
163+
useDeprecatedNextContext: boolean;
164+
useDeprecatedSynchronousErrorHandling: boolean;
165+
}
166+
165167
export interface GroupedObservable<K, T> extends Observable<T> {
166168
readonly key: K;
167169
}

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,4 @@ export { NEVER } from './internal/observable/never';
9898
export * from './internal/types';
9999

100100
/* Config */
101-
export { config } from './internal/config';
101+
export { config, GlobalConfig } from './internal/config';

src/internal/config.ts

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
import { Subscriber } from './Subscriber';
22
import { ObservableNotification } from './types';
33

4+
/**
5+
* The {@link GlobalConfig} object for RxJS. It is used to configure things
6+
* like how to react on unhandled errors.
7+
*/
8+
export const config: GlobalConfig = {
9+
onUnhandledError: null,
10+
onStoppedNotification: null,
11+
Promise: undefined,
12+
useDeprecatedSynchronousErrorHandling: false,
13+
useDeprecatedNextContext: false,
14+
};
15+
416
/**
517
* The global configuration object for RxJS, used to configure things
6-
* like what Promise constructor should used to create Promises
18+
* like how to react on unhandled errors. Accessible via {@link config}
19+
* object.
720
*/
8-
export const config = {
21+
export interface GlobalConfig {
922
/**
1023
* A registration point for unhandled errors from RxJS. These are errors that
1124
* cannot were not handled by consuming code in the usual subscription path. For
@@ -15,7 +28,7 @@ export const config = {
1528
* we do not want errors thrown in this user-configured handler to interfere with the
1629
* behavior of the library.
1730
*/
18-
onUnhandledError: null as ((err: any) => void) | null,
31+
onUnhandledError: ((err: any) => void) | null;
1932

2033
/**
2134
* A registration point for notifications that cannot be sent to subscribers because they
@@ -27,17 +40,17 @@ export const config = {
2740
* we do not want errors thrown in this user-configured handler to interfere with the
2841
* behavior of the library.
2942
*/
30-
onStoppedNotification: null as ((notification: ObservableNotification<any>, subscriber: Subscriber<any>) => void) | null,
43+
onStoppedNotification: ((notification: ObservableNotification<any>, subscriber: Subscriber<any>) => void) | null;
3144

3245
/**
33-
* The promise constructor used by default for methods such as
34-
* {@link toPromise} and {@link forEach}
46+
* The promise constructor used by default for {@link toPromise} and {@link forEach}
47+
* methods.
3548
*
3649
* @deprecated As of version 8, RxJS will no longer support this sort of injection of a
3750
* Promise constructor. If you need a Promise implementation other than native promises,
3851
* please polyfill/patch Promise as you see appropriate. Will be removed in v8.
3952
*/
40-
Promise: undefined as PromiseConstructorLike | undefined,
53+
Promise?: PromiseConstructorLike;
4154

4255
/**
4356
* If true, turns on synchronous error rethrowing, which is a deprecated behavior
@@ -51,7 +64,7 @@ export const config = {
5164
* of unhandled errors. All errors will be thrown on a separate call stack to prevent bad
5265
* behaviors described above. Will be removed in v8.
5366
*/
54-
useDeprecatedSynchronousErrorHandling: false,
67+
useDeprecatedSynchronousErrorHandling: boolean;
5568

5669
/**
5770
* If true, enables an as-of-yet undocumented feature from v5: The ability to access
@@ -67,5 +80,5 @@ export const config = {
6780
* you will have access to a subscription or a signal or token that will allow you to do things like
6881
* unsubscribe and test closed status. Will be removed in v8.
6982
*/
70-
useDeprecatedNextContext: false,
71-
};
83+
useDeprecatedNextContext: boolean;
84+
}

0 commit comments

Comments
 (0)