Skip to content
This repository was archived by the owner on Apr 30, 2021. It is now read-only.

Commit 5442a6a

Browse files
author
Yevgeny Pats
authored
Merge pull request #18 from rhysd/typing-__coverage__
Give typings to global.__coverage__ to avoid @ts-ignore
2 parents 2132223 + c696561 commit 5442a6a

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

src/lib.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
declare module NodeJS {
2+
interface Global {
3+
__coverage__: {
4+
[filePath: string]: {
5+
s: { [n: string]: number };
6+
f: { [n: string]: number };
7+
b: { [n: string]: number[] };
8+
};
9+
};
10+
}
11+
}

src/worker.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,15 @@ class Worker {
1919

2020
getTotalCoverage() {
2121
let total = 0;
22-
// @ts-ignore
23-
for (const filePath in global["__coverage__"]) {
24-
// @ts-ignore
25-
for (const s in global["__coverage__"][filePath]['s']) {
26-
// @ts-ignore
27-
total += global["__coverage__"][filePath]['s'][s] ? 1 : 0;
22+
for (const filePath in global.__coverage__) {
23+
for (const s in global.__coverage__[filePath].s) {
24+
total += global.__coverage__[filePath].s[s] ? 1 : 0;
2825
}
29-
// @ts-ignore
30-
for (const f in global["__coverage__"][filePath]['f']) {
31-
// @ts-ignore
32-
total += global["__coverage__"][filePath]['f'][f] ? 1 : 0;
26+
for (const f in global.__coverage__[filePath].f) {
27+
total += global.__coverage__[filePath].f[f] ? 1 : 0;
3328
}
34-
// @ts-ignore
35-
for (const b in global["__coverage__"][filePath]['b']) {
36-
// @ts-ignore
37-
for (const i of global["__coverage__"][filePath]['b'][b]) {
29+
for (const b in global.__coverage__[filePath].b) {
30+
for (const i of global.__coverage__[filePath].b[b]) {
3831
total += i ? 1 : 0;
3932
}
4033
}
@@ -44,8 +37,7 @@ class Worker {
4437
}
4538

4639
dump_coverage() {
47-
// @ts-ignore
48-
const data = JSON.stringify(global["__coverage__"]);
40+
const data = JSON.stringify(global.__coverage__);
4941
if (!fs.existsSync('./.nyc_output')){
5042
fs.mkdirSync('./.nyc_output');
5143
}

0 commit comments

Comments
 (0)