Skip to content

Commit 0131f7f

Browse files
Upgrade TypeScript (#102)
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
1 parent 2af8cf9 commit 0131f7f

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,20 @@
4848
"@sindresorhus/tsconfig": "^0.6.0",
4949
"@types/benchmark": "^1.0.31",
5050
"@types/node": "^12.12.7",
51-
"@typescript-eslint/eslint-plugin": "^1.11.0",
52-
"@typescript-eslint/parser": "^1.11.0",
51+
"@typescript-eslint/eslint-plugin": "^2.25.0",
52+
"@typescript-eslint/parser": "^2.25.0",
5353
"ava": "^2.0.0",
5454
"benchmark": "^2.1.4",
5555
"codecov": "^3.3.0",
5656
"del-cli": "^3.0.0",
5757
"delay": "^4.2.0",
58-
"eslint-config-xo-typescript": "^0.16.0",
58+
"eslint-config-xo-typescript": "^0.27.0",
5959
"in-range": "^2.0.0",
6060
"nyc": "^14.0.0",
6161
"random-int": "^2.0.0",
6262
"time-span": "^3.1.0",
6363
"ts-node": "^8.3.0",
64-
"typescript": "3.7.2",
64+
"typescript": "3.8.3",
6565
"xo": "^0.25.3"
6666
},
6767
"ava": {

source/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ type Task<TaskResultType> =
1010
| (() => PromiseLike<TaskResultType>)
1111
| (() => TaskResultType);
1212

13+
// eslint-disable-next-line @typescript-eslint/no-empty-function
1314
const empty = (): void => {};
1415

1516
const timeoutError = new TimeoutError();
@@ -56,7 +57,7 @@ export default class PQueue<QueueType extends Queue<RunFunction, EnqueueOptionsT
5657
constructor(options?: Options<QueueType, EnqueueOptionsType>) {
5758
super();
5859

59-
// eslint-disable-next-line @typescript-eslint/no-object-literal-type-assertion
60+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
6061
options = {
6162
carryoverConcurrencyCount: false,
6263
intervalCap: Infinity,
@@ -65,15 +66,14 @@ export default class PQueue<QueueType extends Queue<RunFunction, EnqueueOptionsT
6566
autoStart: true,
6667
queueClass: PriorityQueue,
6768
...options
68-
// TODO: Remove this `as`.
6969
} as Options<QueueType, EnqueueOptionsType>;
7070

7171
if (!(typeof options.intervalCap === 'number' && options.intervalCap >= 1)) {
72-
throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${options.intervalCap}\` (${typeof options.intervalCap})`);
72+
throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${options.intervalCap?.toString() ?? ''}\` (${typeof options.intervalCap})`);
7373
}
7474

7575
if (options.interval === undefined || !(Number.isFinite(options.interval) && options.interval >= 0)) {
76-
throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${options.interval}\` (${typeof options.interval})`);
76+
throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${options.interval?.toString() ?? ''}\` (${typeof options.interval})`);
7777
}
7878

7979
this._carryoverConcurrencyCount = options.carryoverConcurrencyCount!;
@@ -226,6 +226,7 @@ export default class PQueue<QueueType extends Queue<RunFunction, EnqueueOptionsT
226226
/**
227227
Adds a sync or async task to the queue. Always returns a promise.
228228
*/
229+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
229230
async add<TaskResultType>(fn: Task<TaskResultType>, options: Partial<EnqueueOptionsType> = {}): Promise<TaskResultType> {
230231
return new Promise<TaskResultType>((resolve, reject) => {
231232
const run = async (): Promise<void> => {
@@ -349,7 +350,7 @@ export default class PQueue<QueueType extends Queue<RunFunction, EnqueueOptionsT
349350
350351
For example, this can be used to find the number of items remaining in the queue with a specific priority level.
351352
*/
352-
sizeBy(options: Partial<EnqueueOptionsType>): number {
353+
sizeBy(options: Readonly<Partial<EnqueueOptionsType>>): number {
353354
return this._queue.filter(options).length;
354355
}
355356

source/priority-queue.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,22 @@ export default class PriorityQueue implements Queue<RunFunction, PriorityQueueOp
2525
return;
2626
}
2727

28-
const index = lowerBound(this._queue, element, (a, b) => b.priority! - a.priority!);
28+
const index = lowerBound(
29+
this._queue, element,
30+
(a: Readonly<PriorityQueueOptions>, b: Readonly<PriorityQueueOptions>) => b.priority! - a.priority!
31+
);
2932
this._queue.splice(index, 0, element);
3033
}
3134

3235
dequeue(): RunFunction | undefined {
3336
const item = this._queue.shift();
34-
return item && item.run;
37+
return item?.run;
3538
}
3639

37-
filter(options: Partial<PriorityQueueOptions>): RunFunction[] {
38-
return this._queue.filter(element => element.priority === options.priority).map(element => element.run);
40+
filter(options: Readonly<Partial<PriorityQueueOptions>>): RunFunction[] {
41+
return this._queue.filter(
42+
(element: Readonly<PriorityQueueOptions>) => element.priority === options.priority
43+
).map((element: Readonly<{ run: RunFunction }>) => element.run);
3944
}
4045

4146
get size(): number {

0 commit comments

Comments
 (0)