Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove eslint/no-explicit-any and replace with proper types/interfaces #1683

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions components/back-link/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ export const BackLink: BackLinkType = React.forwardRef(

export interface BackLinkType extends React.ForwardRefExoticComponent<BackLinkOwnProps> {
(props: BackLinkPropsWithoutAs, ref?: BackLinkRefType): React.ReactElement<BackLinkPropsWithoutAs>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
<AsC extends string | React.ComponentType<any> = 'a', FAsC extends string | React.ComponentType<any> = AsC>(
<
AsC extends string | React.ComponentType<BackLinkOwnProps> = 'a',
FAsC extends string | React.ComponentType<BackLinkOwnProps> = AsC
>(
props: BackLinkPropsWithAs<AsC, FAsC>,
ref?: React.Ref<AsC>
): React.ReactElement<BackLinkPropsWithAs<AsC, FAsC>>;
Expand All @@ -73,10 +75,8 @@ type BackLinkPropsWithoutAs = StyledComponentProps<'a', never, BackLinkOwnProps,
};

type BackLinkPropsWithAs<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
AsC extends string | React.ComponentType<any>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
FAsC extends string | React.ComponentType<any> = AsC
AsC extends string | React.ComponentType<BackLinkOwnProps>,
FAsC extends string | React.ComponentType<BackLinkOwnProps> = AsC
> = StyledComponentProps<AsC, never, BackLinkOwnProps, never, FAsC> & {
as?: AsC | undefined;
forwardedAs?: FAsC | undefined;
Expand Down
16 changes: 8 additions & 8 deletions components/button/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import type { StyledComponentProps } from 'styled-components';

import type { WithWhiteSpaceProps } from '@govuk-react/lib';

import styled from 'styled-components';
import * as React from 'react';
import { BORDER_WIDTH_FORM_ELEMENT, FOCUSABLE, MEDIA_QUERIES, SPACING_POINTS } from '@govuk-react/constants';
import { spacing, typography } from '@govuk-react/lib';
import { BUTTON_COLOUR, BUTTON_COLOUR_DARKEN_15, WHITE } from 'govuk-colours';
import { darken, stripUnit } from 'polished';
import * as React from 'react';
import styled from 'styled-components';

const BUTTON_SHADOW_SIZE = BORDER_WIDTH_FORM_ELEMENT;
const RAW_SPACING_2 = SPACING_POINTS[2];
Expand Down Expand Up @@ -231,8 +231,10 @@ type ButtonRefType = React.Ref<HTMLButtonElement>;

export interface ButtonType extends React.ForwardRefExoticComponent<ButtonOwnProps> {
(props: ButtonPropsWithoutAs, ref?: ButtonRefType): React.ReactElement<ButtonPropsWithoutAs>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
<AsC extends string | React.ComponentType<any> = 'button', FAsC extends string | React.ComponentType<any> = AsC>(
<
AsC extends string | React.ComponentType<ButtonOwnProps> = 'button',
FAsC extends string | React.ComponentType<ButtonOwnProps> = AsC
>(
props: ButtonPropsWithAs<AsC, FAsC>,
ref?: React.Ref<AsC>
): React.ReactElement<ButtonPropsWithAs<AsC, FAsC>>;
Expand All @@ -244,10 +246,8 @@ type ButtonPropsWithoutAs = StyledComponentProps<'button', never, ButtonOwnProps
};

type ButtonPropsWithAs<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
AsC extends string | React.ComponentType<any>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
FAsC extends string | React.ComponentType<any> = AsC
AsC extends string | React.ComponentType<ButtonOwnProps>,
FAsC extends string | React.ComponentType<ButtonOwnProps> = AsC
> = StyledComponentProps<AsC, never, ButtonOwnProps, never, FAsC> & {
as?: AsC | undefined;
forwardedAs?: FAsC | undefined;
Expand Down
12 changes: 6 additions & 6 deletions components/grid-col/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,10 @@ export const GridCol: GridColType = React.forwardRef(

export interface GridColType extends React.ForwardRefExoticComponent<GridColOwnProps> {
(props: GridColPropsWithoutAs, ref?: GridColRefType): React.ReactElement<GridColPropsWithoutAs>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
<AsC extends string | React.ComponentType<any> = 'div', FAsC extends string | React.ComponentType<any> = AsC>(
<
AsC extends string | React.ComponentType<GridColOwnProps> = 'div',
FAsC extends string | React.ComponentType<GridColOwnProps> = AsC
>(
props: GridColPropsWithAs<AsC, FAsC>,
ref?: React.Ref<AsC>
): React.ReactElement<GridColPropsWithAs<AsC, FAsC>>;
Expand All @@ -160,10 +162,8 @@ type GridColPropsWithoutAs = StyledComponentProps<'div', never, GridColOwnProps,
};

type GridColPropsWithAs<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
AsC extends string | React.ComponentType<any>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
FAsC extends string | React.ComponentType<any> = AsC
AsC extends string | React.ComponentType<GridColOwnProps>,
FAsC extends string | React.ComponentType<GridColOwnProps> = AsC
> = StyledComponentProps<AsC, never, GridColOwnProps, never, FAsC> & {
as?: AsC | undefined;
forwardedAs?: FAsC | undefined;
Expand Down
16 changes: 8 additions & 8 deletions components/heading/src/heading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import type { StyledComponentProps } from 'styled-components';

import type { WithWhiteSpaceProps } from '@govuk-react/lib';

import styled from 'styled-components';
import * as React from 'react';
import { HEADING_SIZES, LEVEL_SIZE, LEVEL_TAG, MEDIA_QUERIES, TYPOGRAPHY_SCALE } from '@govuk-react/constants';
import { spacing, typography } from '@govuk-react/lib';
import * as React from 'react';
import styled from 'styled-components';

// use `size` only with string for XLARGE, SMALL etc and number for px size
// so if `size` is a string, we find a numeric size based off `HEADING_SIZES`
Expand Down Expand Up @@ -69,8 +69,10 @@ Heading.displayName = 'Heading';

export interface HeadingType extends React.FC<HeadingOwnProps & WithWhiteSpaceProps> {
(props: HeadingPropsWithoutAs): React.ReactElement<HeadingPropsWithoutAs>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
<AsC extends string | React.ComponentType<any> = 'h1', FAsC extends string | React.ComponentType<any> = AsC>(
<
AsC extends string | React.ComponentType<HeadingType> = 'h1',
FAsC extends string | React.ComponentType<HeadingType> = AsC
>(
props: HeadingPropsWithAs<AsC, FAsC>
): React.ReactElement<HeadingPropsWithAs<AsC, FAsC>>;
}
Expand All @@ -81,10 +83,8 @@ type HeadingPropsWithoutAs = StyledComponentProps<'h1', never, HeadingOwnProps,
};

type HeadingPropsWithAs<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
AsC extends string | React.ComponentType<any>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
FAsC extends string | React.ComponentType<any> = AsC
AsC extends string | React.ComponentType<HeadingType>,
FAsC extends string | React.ComponentType<HeadingType> = AsC
> = StyledComponentProps<AsC, never, HeadingOwnProps, never, FAsC> & {
as?: AsC | undefined;
forwardedAs?: FAsC | undefined;
Expand Down
16 changes: 8 additions & 8 deletions components/pagination/src/anchor.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { StyledComponentProps } from 'styled-components';

import { FONT_SIZE, LINE_HEIGHT, MEDIA_QUERIES, NTA_LIGHT, SPACING } from '@govuk-react/constants';
import { BLUE, GREY_4, PURPLE, WHITE, YELLOW } from 'govuk-colours';
import * as React from 'react';
import styled from 'styled-components';
import { BLUE, GREY_4, PURPLE, YELLOW, WHITE } from 'govuk-colours';
import { FONT_SIZE, LINE_HEIGHT, SPACING, MEDIA_QUERIES, NTA_LIGHT } from '@govuk-react/constants';

import { ArrowRight as NextPageIcon, ArrowLeft as PrevPageIcon } from '@govuk-react/icons';

Expand Down Expand Up @@ -114,8 +114,10 @@ const PaginationAnchor: PaginationAnchorType = ({

interface PaginationAnchorType extends React.FC<PaginationAnchorProps> {
(props: PaginationAnchorPropsWithoutAs): React.ReactElement<PaginationAnchorPropsWithoutAs>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
<AsC extends string | React.ComponentType<any> = 'a', FAsC extends string | React.ComponentType<any> = AsC>(
<
AsC extends string | React.ComponentType<PaginationAnchorProps> = 'a',
FAsC extends string | React.ComponentType<PaginationAnchorProps> = AsC
>(
props: PaginationAnchorPropsWithAs<AsC, FAsC>
): React.ReactElement<PaginationAnchorPropsWithAs<AsC, FAsC>>;
}
Expand All @@ -126,10 +128,8 @@ type PaginationAnchorPropsWithoutAs = StyledComponentProps<'a', never, Paginatio
};

type PaginationAnchorPropsWithAs<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
AsC extends string | React.ComponentType<any>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
FAsC extends string | React.ComponentType<any> = AsC
AsC extends string | React.ComponentType<PaginationAnchorProps>,
FAsC extends string | React.ComponentType<PaginationAnchorProps> = AsC
> = StyledComponentProps<AsC, never, PaginationAnchorProps, never, FAsC> & {
as?: AsC | undefined;
forwardedAs?: FAsC | undefined;
Expand Down
12 changes: 6 additions & 6 deletions components/skip-link/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ export const SkipLink: SkipLinkType = React.forwardRef(

export interface SkipLinkType extends React.ForwardRefExoticComponent<SkipLinkOwnProps> {
(props: SkipLinkPropsWithoutAs, ref?: SkipLinkRefType): React.ReactElement<SkipLinkPropsWithoutAs>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
<AsC extends string | React.ComponentType<any> = 'a', FAsC extends string | React.ComponentType<any> = AsC>(
<
AsC extends string | React.ComponentType<SkipLinkOwnProps> = 'a',
FAsC extends string | React.ComponentType<SkipLinkOwnProps> = AsC
>(
props: SkipLinkPropsWithAs<AsC, FAsC>,
ref?: React.Ref<AsC>
): React.ReactElement<SkipLinkPropsWithAs<AsC, FAsC>>;
Expand All @@ -60,10 +62,8 @@ type SkipLinkPropsWithoutAs = StyledComponentProps<'a', never, SkipLinkOwnProps,
};

type SkipLinkPropsWithAs<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
AsC extends string | React.ComponentType<any>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
FAsC extends string | React.ComponentType<any> = AsC
AsC extends string | React.ComponentType<SkipLinkOwnProps>,
FAsC extends string | React.ComponentType<SkipLinkOwnProps> = AsC
> = StyledComponentProps<AsC, never, SkipLinkOwnProps, never, FAsC> & {
as?: AsC | undefined;
forwardedAs?: FAsC | undefined;
Expand Down
12 changes: 6 additions & 6 deletions components/tabs/src/atoms/tab/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ const Tab: TabType = ({ selected = false, ...props }: TabOwnProps) => (

interface TabType extends React.FC<TabOwnProps> {
(props: TabPropsWithoutAs): React.ReactElement<TabPropsWithoutAs>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
<AsC extends string | React.ComponentType<any> = 'a', FAsC extends string | React.ComponentType<any> = AsC>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the any here is so that, if you are using the as prop, you can pass any props to the component that will then be forwarded on to the as component

<
AsC extends string | React.ComponentType<TabOwnProps> = 'a',
FAsC extends string | React.ComponentType<TabOwnProps> = AsC
>(
props: TabPropsWithAs<AsC, FAsC>
): React.ReactElement<TabPropsWithAs<AsC, FAsC>>;
}
Expand All @@ -86,10 +88,8 @@ type TabPropsWithoutAs = StyledComponentProps<'a', never, TabOwnProps, never> &
};

type TabPropsWithAs<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
AsC extends string | React.ComponentType<any>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
FAsC extends string | React.ComponentType<any> = AsC
AsC extends string | React.ComponentType<TabOwnProps>,
FAsC extends string | React.ComponentType<TabOwnProps> = AsC
> = StyledComponentProps<AsC, never, TabOwnProps, never, FAsC> & {
as?: AsC | undefined;
forwardedAs?: FAsC | undefined;
Expand Down
Loading