Skip to content

Commit dd0a120

Browse files
committed
chore: rm types on hasOwnProperty
1 parent 5e25287 commit dd0a120

7 files changed

Lines changed: 29 additions & 39 deletions

File tree

packages/vkui/global.d.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,3 @@ interface MediaQueryList {
2323
options?: boolean | EventListenerOptions,
2424
) => void);
2525
}
26-
27-
// см. https://github.com/microsoft/TypeScript/issues/18282
28-
interface Object {
29-
// eslint-disable-next-line @typescript-eslint/method-signature-style
30-
hasOwnProperty<T>(this: T, v: PropertyKey): v is keyof T;
31-
}

packages/vkui/src/components/AppRoot/helpers.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,18 @@ export function getSafeAreaInsetsAsCssVariables(
3131
return {};
3232
}
3333

34-
const cssVariables: Record<string, string> = {};
34+
const cssVariables = Object.entries(safeAreaInsets).reduce<Record<string, string>>(
35+
(result, [key, value]) => {
36+
if (value === undefined) {
37+
return result;
38+
}
3539

36-
for (const key in safeAreaInsets) {
37-
if (safeAreaInsets.hasOwnProperty(key) && typeof safeAreaInsets[key] === 'number') {
38-
const propertyKey = `${CUSTOM_PROPERTY_INSET_PREFIX}${key}`;
39-
const propertyValue = safeAreaInsets[key];
40+
result[`${CUSTOM_PROPERTY_INSET_PREFIX}${key}`] = `${value}px`;
4041

41-
cssVariables[propertyKey] = `${propertyValue}px`;
42-
}
43-
}
42+
return result;
43+
},
44+
{},
45+
);
4446

4547
return cssVariables;
4648
}

packages/vkui/src/components/ModalPage/ModalPageInternal.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ export const ModalPageInternal = ({
225225
);
226226
};
227227

228-
const desktopMaxWidthClassNames = {
228+
const desktopMaxWidthClassNames: Record<string, string | undefined> = {
229229
s: styles.hostDesktopMaxWidthS,
230230
m: styles.hostDesktopMaxWidthM,
231231
l: styles.hostDesktopMaxWidthL,
@@ -238,9 +238,12 @@ function resolveDesktopMaxWidth(
238238
return [undefined, { '--vkui_internal_ModalPage--desktopMaxWidth': `${desktopMaxWidth}px` }];
239239
}
240240

241-
return desktopMaxWidthClassNames.hasOwnProperty(desktopMaxWidth)
242-
? [desktopMaxWidthClassNames[desktopMaxWidth], undefined]
243-
: [undefined, { '--vkui_internal_ModalPage--desktopMaxWidth': desktopMaxWidth }];
241+
const className = desktopMaxWidthClassNames[desktopMaxWidth];
242+
const style = className
243+
? undefined
244+
: { '--vkui_internal_ModalPage--desktopMaxWidth': desktopMaxWidth };
245+
246+
return [className, style];
244247
}
245248

246249
function getHeightCSSVariable(height?: number | string): CSSCustomProperties | undefined {

packages/vkui/src/helpers/getValueByKey.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ describe('getRequiredValueByKey', () => {
77
});
88

99
it('should throw error when key does not exist', () => {
10-
const map = { key1: 'value1' };
11-
// @ts-expect-error: TS2345 функция, как и задумано, ругается на то, что ключа key2 нет в map
10+
const map: Record<string, string> = { key1: 'value1' };
1211
expect(() => getRequiredValueByKey('key2', map)).toThrow('getRequiredValueByKey(key2)');
1312
});
1413
});

packages/vkui/src/helpers/getValueByKey.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@ export const getRequiredValueByKey = <VALUE, KEY extends PropertyKey = PropertyK
33
map: Record<KEY, VALUE>,
44
): VALUE => {
55
if (!map.hasOwnProperty(key)) {
6-
throw new Error(`getRequiredValueByKey(${key})`);
6+
throw new Error(`getRequiredValueByKey(${String(key)})`);
77
}
88
return map[key];
99
};
1010

1111
export const getValueByKey = <VALUE, KEY extends PropertyKey = PropertyKey>(
1212
key: KEY,
13-
map: {
14-
[key: string]: VALUE;
15-
},
13+
map: Record<any, VALUE>,
1614
defaultValue: VALUE,
1715
): VALUE => {
1816
if (!map.hasOwnProperty(key)) {

packages/vkui/src/lib/animation/useCSSKeyframesAnimationController.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ describe(useCSSKeyframesAnimationController, () => {
1313
};
1414

1515
beforeEach(() => {
16-
for (const key in callbacks) {
17-
if (callbacks.hasOwnProperty(key)) {
18-
callbacks[key].mockClear();
19-
}
20-
}
16+
Object.values(callbacks).forEach((callback) => {
17+
callback.mockClear();
18+
});
2119
});
2220

2321
describe.each([

packages/vkui/src/lib/animation/useCSSTransition.test.tsx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,15 @@ describe(useCSSTransition, () => {
1313
};
1414

1515
beforeEach(() => {
16-
for (const key in callbacks) {
17-
if (callbacks.hasOwnProperty(key)) {
18-
callbacks[key].mockClear();
19-
}
20-
}
16+
Object.values(callbacks).forEach((value) => {
17+
value.mockClear();
18+
});
2119
});
2220

2321
const expectEveryCallbacksHaveNotBeenCalled = () => {
24-
for (const key in callbacks) {
25-
if (callbacks.hasOwnProperty(key)) {
26-
expect(callbacks[key]).toHaveBeenCalledTimes(0);
27-
}
28-
}
22+
Object.values(callbacks).forEach((value) => {
23+
expect(value).toHaveBeenCalledTimes(0);
24+
});
2925
};
3026

3127
describe('first mount', () => {

0 commit comments

Comments
 (0)