Skip to content

Commit 65d93ec

Browse files
committed
fix: resolve ts lint explicit any
type MediaQueryHandler
1 parent c2e9f18 commit 65d93ec

6 files changed

Lines changed: 21 additions & 11 deletions

File tree

components/AnchoredHeading.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { FC, PropsWithChildren } from 'react';
1+
import type { FC, JSX, PropsWithChildren } from 'react';
22

33
type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;
44

@@ -18,15 +18,15 @@ type AnchorHeadingProps = PropsWithChildren<{
1818
*
1919
* If your title has some non-English characters, please use
2020
* `<!---->` to quote your English anchor name inside, with your
21-
* own title beside it. Otherwises it will return you what it is.
21+
* own title beside it. Otherwise it will return you what it is.
2222
*/
2323

2424
// React will ignore "<!" and ">" in the string,
2525
// so we can just use '-- --' to quote the anchor name inside it.
2626
const COMMENT_FOR_HEADANCHOR = /--\x20?([\w\x20-]+)\x20?--/;
2727

2828
const AnchoredHeading: FC<AnchorHeadingProps> = ({ level, id, children }) => {
29-
const HeadingLevelTag = `h${level}` as any;
29+
const HeadingLevelTag = `h${level}` as unknown as JSX.ElementType;
3030

3131
let sanitizedId =
3232
id ?? children?.toLocaleString().toLocaleLowerCase().replace(/\x20/g, '-');

components/SideNavigation.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { FC } from 'react';
77

88
type SideNavigationProps = {
99
navigationKey: NavigationKeys;
10+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1011
context?: Record<string, Record<string, any>>;
1112
};
1213

hooks/__tests__/useMediaQuery.test.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { renderHook } from '@testing-library/react';
22
import { useMediaQuery } from '@/hooks/useMediaQuery';
3+
import type { MediaQueryHandler } from '@/hooks/useMediaQuery';
34

45
describe('useMediaQuery', () => {
56
it('should check for matchMedia support', () => {
@@ -41,7 +42,7 @@ describe('useMediaQuery', () => {
4142
it('should subscribe for media changes', () => {
4243
const listenerMock = jest
4344
.fn()
44-
.mockImplementation((_: any, handler: Function) => {
45+
.mockImplementation((_: unknown, handler: MediaQueryHandler) => {
4546
handler();
4647
});
4748

@@ -60,9 +61,11 @@ describe('useMediaQuery', () => {
6061
});
6162

6263
it("should support MediaQueryList's old event listeners", () => {
63-
const listenerMock = jest.fn().mockImplementation((handler: Function) => {
64-
handler();
65-
});
64+
const listenerMock = jest
65+
.fn()
66+
.mockImplementation((handler: MediaQueryHandler) => {
67+
handler();
68+
});
6669

6770
Object.defineProperty(window, 'matchMedia', {
6871
writable: true,

hooks/useMediaQuery.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { useState, useEffect } from 'react';
22

3-
const mediaQueryChangeSubscribe = (mq: MediaQueryList, handler: () => void) => {
3+
export type MediaQueryHandler = () => void;
4+
5+
const mediaQueryChangeSubscribe = (
6+
mq: MediaQueryList,
7+
handler: MediaQueryHandler
8+
) => {
49
if (mq.addEventListener) {
510
mq.addEventListener('change', handler);
611
} else {
@@ -10,7 +15,7 @@ const mediaQueryChangeSubscribe = (mq: MediaQueryList, handler: () => void) => {
1015

1116
const mediaQueryChangeUnsubscribe = (
1217
mq: MediaQueryList,
13-
handler: () => void
18+
handler: MediaQueryHandler
1419
) => {
1520
if (mq.removeEventListener) {
1621
mq.removeEventListener('change', handler);

hooks/useNavigation.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
12
import { FormattedMessage } from 'react-intl';
23
import * as nextJson from '@/next.json.mjs';
34
import type { NavigationEntry, NavigationKeys } from '@/types';

util/nodeRelease.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import type {
44
NodeReleaseSupport,
55
} from '@/types/releases';
66

7-
export const isNodeRelease = (release: any): release is NodeRelease =>
8-
typeof release === 'object' && release?.version;
7+
export const isNodeRelease = (release: unknown): release is NodeRelease =>
8+
typeof release === 'object' && release !== null && 'version' in release;
99

1010
export const getNodeReleaseStatus = (
1111
now: Date,

0 commit comments

Comments
 (0)