Skip to content

Commit 57e4ad3

Browse files
committed
fix types
1 parent f0c671c commit 57e4ad3

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/types/window.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@ interface Window {
4545

4646
api: import('../services/api/index').YdbEmbeddedAPI;
4747

48-
[key: `yaCounter${number}`]: number;
48+
[key: `yaCounter${number}`]: any;
4949
}

src/utils/yaMetrica.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import {uiFactory} from '../uiFactory/uiFactory';
22

3+
export interface Counter {
4+
hit: (...args: unknown[]) => void;
5+
params: (...args: unknown[]) => void;
6+
userParams: (...args: unknown[]) => void;
7+
reachGoal: (...args: unknown[]) => void;
8+
}
9+
310
const yaMetricaId = uiFactory.yaMetricaId;
411

5-
class FakeMetrica {
12+
class FakeMetrica implements Counter {
613
private warnShown = false;
714

815
hit() {
@@ -23,14 +30,16 @@ class FakeMetrica {
2330

2431
private warnOnce() {
2532
if (!this.warnShown) {
26-
console.warn('YaMetrica counter is not defined');
33+
console.warn('YaMetrica counter is not defined\n');
2734
this.warnShown = true;
2835
}
2936
}
3037
}
3138

3239
export function getMetrica() {
33-
const metricaInstance = yaMetricaId && window[`yaCounter${yaMetricaId}`];
40+
const metricaInstance = yaMetricaId
41+
? (window[`yaCounter${yaMetricaId}`] as Counter)
42+
: undefined;
3443

3544
return metricaInstance ?? new FakeMetrica();
3645
}

0 commit comments

Comments
 (0)