Skip to content

Commit fce9aa1

Browse files
authored
fix: Now compatible with TypeScript 4.6 type checks (#6895)
* fix(typescript): type check failures in typescript 4.6 * fix(timers): TimerHandle type to resolve node/browser timer handle types setInterval/setTimeout/setImmediate have different return types in node.js and the browser. Define TimerHandle to abstract the difference and fix compilation errors where the return type was a number. * Use `export type` for re-exporting type definitions Fixes compilation under typescript with `isolatedModules: true` See https://devblogs.microsoft.com/typescript/announcing-typescript-3-8/#type-only-imports-exports
1 parent 708c0a7 commit fce9aa1

File tree

16 files changed

+65
-41
lines changed

16 files changed

+65
-41
lines changed

spec/ajax/index-spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ describe('index', () => {
77
});
88

99
it('should export Ajax data classes', () => {
10-
expect(index.AjaxResponse).to.exist;
1110
expect(index.AjaxError).to.exist;
1211
expect(index.AjaxTimeoutError).to.exist;
1312
// Interfaces can be checked by creating a variable of that type
1413
let ajaxRequest: index.AjaxRequest;
14+
let ajaxResponse: index.AjaxResponse<object>;
1515
});
1616
});

src/ajax/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export { ajax } from '../internal/ajax/ajax';
22
export { AjaxError, AjaxTimeoutError } from '../internal/ajax/errors';
33
export { AjaxResponse } from '../internal/ajax/AjaxResponse';
4-
export { AjaxRequest, AjaxConfig, AjaxDirection } from '../internal/ajax/types';
4+
export type { AjaxRequest, AjaxConfig, AjaxDirection } from '../internal/ajax/types';

src/index.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
/* Observable */
1616
export { Observable } from './internal/Observable';
1717
export { ConnectableObservable } from './internal/observable/ConnectableObservable';
18-
export { GroupedObservable } from './internal/operators/groupBy';
19-
export { Operator } from './internal/Operator';
18+
export type { GroupedObservable } from './internal/operators/groupBy';
19+
export type { Operator } from './internal/Operator';
2020
export { observable } from './internal/symbol/observable';
2121
export { animationFrames } from './internal/observable/dom/animationFrames';
2222

@@ -97,7 +97,8 @@ export { NEVER } from './internal/observable/never';
9797
export * from './internal/types';
9898

9999
/* Config */
100-
export { config, GlobalConfig } from './internal/config';
100+
export { config } from './internal/config';
101+
export type { GlobalConfig } from './internal/config';
101102

102103
/* Operators */
103104
export { audit } from './internal/operators/audit';
@@ -115,7 +116,8 @@ export { concatAll } from './internal/operators/concatAll';
115116
export { concatMap } from './internal/operators/concatMap';
116117
export { concatMapTo } from './internal/operators/concatMapTo';
117118
export { concatWith } from './internal/operators/concatWith';
118-
export { connect, ConnectConfig } from './internal/operators/connect';
119+
export { connect } from './internal/operators/connect';
120+
export type { ConnectConfig } from './internal/operators/connect';
119121
export { count } from './internal/operators/count';
120122
export { debounce } from './internal/operators/debounce';
121123
export { debounceTime } from './internal/operators/debounceTime';
@@ -138,7 +140,8 @@ export { finalize } from './internal/operators/finalize';
138140
export { find } from './internal/operators/find';
139141
export { findIndex } from './internal/operators/findIndex';
140142
export { first } from './internal/operators/first';
141-
export { groupBy, BasicGroupByOptions, GroupByOptionsWithElement } from './internal/operators/groupBy';
143+
export { groupBy } from './internal/operators/groupBy';
144+
export type { BasicGroupByOptions, GroupByOptionsWithElement } from './internal/operators/groupBy';
142145
export { ignoreElements } from './internal/operators/ignoreElements';
143146
export { isEmpty } from './internal/operators/isEmpty';
144147
export { last } from './internal/operators/last';
@@ -165,15 +168,18 @@ export { raceWith } from './internal/operators/raceWith';
165168
export { reduce } from './internal/operators/reduce';
166169
export { repeat } from './internal/operators/repeat';
167170
export { repeatWhen } from './internal/operators/repeatWhen';
168-
export { retry, RetryConfig } from './internal/operators/retry';
171+
export { retry } from './internal/operators/retry';
172+
export type { RetryConfig } from './internal/operators/retry';
169173
export { retryWhen } from './internal/operators/retryWhen';
170174
export { refCount } from './internal/operators/refCount';
171175
export { sample } from './internal/operators/sample';
172176
export { sampleTime } from './internal/operators/sampleTime';
173177
export { scan } from './internal/operators/scan';
174178
export { sequenceEqual } from './internal/operators/sequenceEqual';
175-
export { share, ShareConfig } from './internal/operators/share';
176-
export { shareReplay, ShareReplayConfig } from './internal/operators/shareReplay';
179+
export { share } from './internal/operators/share';
180+
export type { ShareConfig } from './internal/operators/share';
181+
export { shareReplay } from './internal/operators/shareReplay';
182+
export type { ShareReplayConfig } from './internal/operators/shareReplay';
177183
export { single } from './internal/operators/single';
178184
export { skip } from './internal/operators/skip';
179185
export { skipLast } from './internal/operators/skipLast';
@@ -190,11 +196,13 @@ export { takeLast } from './internal/operators/takeLast';
190196
export { takeUntil } from './internal/operators/takeUntil';
191197
export { takeWhile } from './internal/operators/takeWhile';
192198
export { tap } from './internal/operators/tap';
193-
export { throttle, ThrottleConfig } from './internal/operators/throttle';
199+
export { throttle } from './internal/operators/throttle';
200+
export type { ThrottleConfig } from './internal/operators/throttle';
194201
export { throttleTime } from './internal/operators/throttleTime';
195202
export { throwIfEmpty } from './internal/operators/throwIfEmpty';
196203
export { timeInterval } from './internal/operators/timeInterval';
197-
export { timeout, TimeoutConfig, TimeoutInfo } from './internal/operators/timeout';
204+
export { timeout } from './internal/operators/timeout';
205+
export type { TimeoutConfig, TimeoutInfo } from './internal/operators/timeout';
198206
export { timeoutWith } from './internal/operators/timeoutWith';
199207
export { timestamp } from './internal/operators/timestamp';
200208
export { toArray } from './internal/operators/toArray';

src/internal/Subscriber.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export class SafeSubscriber<T> extends Subscriber<T> {
203203
// The first argument is a function, not an observer. The next
204204
// two arguments *could* be observers, or they could be empty.
205205
partialObserver = {
206-
next: observerOrNext ?? undefined,
206+
next: (observerOrNext ?? undefined) as (((value: T) => void) | undefined),
207207
error: error ?? undefined,
208208
complete: complete ?? undefined,
209209
};

src/internal/operators/groupBy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export function groupBy<T, K, R>(
147147
return operate((source, subscriber) => {
148148
let element: ((value: any) => any) | void;
149149
if (!elementOrOptions || typeof elementOrOptions === 'function') {
150-
element = elementOrOptions;
150+
element = elementOrOptions as ((value: any) => any);
151151
} else {
152152
({ duration, element, connector } = elementOrOptions);
153153
}

src/internal/operators/retry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export function retry<T>(configOrCount: number | RetryConfig = Infinity): MonoTy
8686
config = configOrCount;
8787
} else {
8888
config = {
89-
count: configOrCount,
89+
count: configOrCount as number,
9090
};
9191
}
9292
const { count = Infinity, delay, resetOnSuccess: resetOnSuccess = false } = config;

src/internal/operators/shareReplay.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export function shareReplay<T>(
161161
if (configOrBufferSize && typeof configOrBufferSize === 'object') {
162162
({ bufferSize = Infinity, windowTime = Infinity, refCount = false, scheduler } = configOrBufferSize);
163163
} else {
164-
bufferSize = configOrBufferSize ?? Infinity;
164+
bufferSize = (configOrBufferSize ?? Infinity) as number;
165165
}
166166
return share<T>({
167167
connector: () => new ReplaySubject(bufferSize, windowTime, scheduler),

src/internal/scheduler/immediateProvider.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { Immediate } from '../util/Immediate';
2+
import type { TimerHandle } from './timerHandle';
23
const { setImmediate, clearImmediate } = Immediate;
34

4-
type SetImmediateFunction = (handler: () => void, ...args: any[]) => number;
5-
type ClearImmediateFunction = (handle: number) => void;
5+
type SetImmediateFunction = (handler: () => void, ...args: any[]) => TimerHandle;
6+
type ClearImmediateFunction = (handle: TimerHandle) => void;
67

78
interface ImmediateProvider {
89
setImmediate: SetImmediateFunction;
@@ -24,7 +25,7 @@ export const immediateProvider: ImmediateProvider = {
2425
},
2526
clearImmediate(handle) {
2627
const { delegate } = immediateProvider;
27-
return (delegate?.clearImmediate || clearImmediate)(handle);
28+
return (delegate?.clearImmediate || clearImmediate)(handle as any);
2829
},
2930
delegate: undefined,
3031
};

src/internal/scheduler/intervalProvider.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
type SetIntervalFunction = (handler: () => void, timeout?: number, ...args: any[]) => number;
2-
type ClearIntervalFunction = (handle: number) => void;
1+
import type { TimerHandle } from './timerHandle';
2+
type SetIntervalFunction = (handler: () => void, timeout?: number, ...args: any[]) => TimerHandle;
3+
type ClearIntervalFunction = (handle: TimerHandle) => void;
34

45
interface IntervalProvider {
56
setInterval: SetIntervalFunction;
@@ -16,15 +17,15 @@ export const intervalProvider: IntervalProvider = {
1617
// When accessing the delegate, use the variable rather than `this` so that
1718
// the functions can be called without being bound to the provider.
1819
setInterval(handler: () => void, timeout?: number, ...args) {
19-
const {delegate} = intervalProvider;
20+
const { delegate } = intervalProvider;
2021
if (delegate?.setInterval) {
2122
return delegate.setInterval(handler, timeout, ...args);
2223
}
2324
return setInterval(handler, timeout, ...args);
2425
},
2526
clearInterval(handle) {
2627
const { delegate } = intervalProvider;
27-
return (delegate?.clearInterval || clearInterval)(handle);
28+
return (delegate?.clearInterval || clearInterval)(handle as any);
2829
},
2930
delegate: undefined,
3031
};

src/internal/scheduler/timeoutProvider.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
type SetTimeoutFunction = (handler: () => void, timeout?: number, ...args: any[]) => number;
2-
type ClearTimeoutFunction = (handle: number) => void;
1+
import type { TimerHandle } from './timerHandle';
2+
type SetTimeoutFunction = (handler: () => void, timeout?: number, ...args: any[]) => TimerHandle;
3+
type ClearTimeoutFunction = (handle: TimerHandle) => void;
34

45
interface TimeoutProvider {
56
setTimeout: SetTimeoutFunction;
@@ -16,15 +17,15 @@ export const timeoutProvider: TimeoutProvider = {
1617
// When accessing the delegate, use the variable rather than `this` so that
1718
// the functions can be called without being bound to the provider.
1819
setTimeout(handler: () => void, timeout?: number, ...args) {
19-
const {delegate} = timeoutProvider;
20+
const { delegate } = timeoutProvider;
2021
if (delegate?.setTimeout) {
2122
return delegate.setTimeout(handler, timeout, ...args);
2223
}
2324
return setTimeout(handler, timeout, ...args);
2425
},
2526
clearTimeout(handle) {
2627
const { delegate } = timeoutProvider;
27-
return (delegate?.clearTimeout || clearTimeout)(handle);
28+
return (delegate?.clearTimeout || clearTimeout)(handle as any);
2829
},
2930
delegate: undefined,
3031
};

0 commit comments

Comments
 (0)