Skip to content

Commit

Permalink
Update eslint rules to use interface instead of type
Browse files Browse the repository at this point in the history
This updates our custom eslint config for `consistent-type-definitions`
to match the default for eslint.  This is also the recommended rule from
typescript iself, saying:

> use interface until you need to use features from type.

https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#differences-between-type-aliases-and-interfaces

Also, especially when building extendible React components, using type
intersection (e.g. type Props = X & Y), is significantly slower than
using interface and extends.

Therefore, to fit with standards, we will stick to using interface
everywhere possible
  • Loading branch information
venables committed Sep 4, 2023
1 parent dcf9e9c commit 311c81e
Show file tree
Hide file tree
Showing 15 changed files with 24 additions and 24 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ module.exports = {
}
},
rules: {
"@typescript-eslint/consistent-type-definitions": ["error", "type"],
"@typescript-eslint/consistent-type-imports": [
"error",
{ prefer: "type-imports", fixStyle: "separate-type-imports" }
Expand Down
2 changes: 1 addition & 1 deletion app/(auth)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ThemePickerProvider } from "@/components/theme-picker/theme-picker-prov

import type { ReactNode } from "react"

type Props = {
interface Props {
children?: ReactNode
}

Expand Down
2 changes: 1 addition & 1 deletion app/(legal)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Button } from "@/components/ui/button"

import type { ReactNode } from "react"

type Props = {
interface Props {
children?: ReactNode
}

Expand Down
2 changes: 1 addition & 1 deletion app/(marketing)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Header } from "@/components/layout/header"

import type { ReactNode } from "react"

type Props = {
interface Props {
children?: ReactNode
}

Expand Down
2 changes: 1 addition & 1 deletion app/api/ping/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { NextResponse } from "next/server"
import { env } from "@/env"
import { handler } from "@/lib/api-fns"

type ResponseData = {
interface ResponseData {
pong: string
}

Expand Down
2 changes: 1 addition & 1 deletion app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { ReactNode } from "react"

const inter = Inter({ variable: "--font-inter", subsets: ["latin"] })

type Props = {
interface Props {
children: ReactNode
}

Expand Down
2 changes: 1 addition & 1 deletion components/auth/external-auth-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const PROVIDERS = {
}
}

type Props = {
interface Props {
provider: keyof typeof PROVIDERS
isLoading?: boolean
setIsLoading?: (isLoading: boolean) => void
Expand Down
2 changes: 1 addition & 1 deletion components/layout/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Logo } from "@/components/icons/brand/logo"
import { Button } from "@/components/ui/button"
import { siteConfig } from "@/config"

type Props = {
interface Props {
user?: { id?: string | null }
}

Expand Down
2 changes: 1 addition & 1 deletion components/spinner/spinner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { cls } from "@/lib/utils"

import styles from "./spinner.module.css"

type Props = {
interface Props {
className?: string
}

Expand Down
5 changes: 3 additions & 2 deletions components/ui/badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ const badgeVariants = cva(
}
)

export type BadgeProps = React.HTMLAttributes<HTMLDivElement> &
VariantProps<typeof badgeVariants>
export interface BadgeProps
extends React.HTMLAttributes<HTMLDivElement>,
VariantProps<typeof badgeVariants> {}

function Badge({ className, variant, ...props }: BadgeProps) {
return (
Expand Down
7 changes: 4 additions & 3 deletions components/ui/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ const buttonVariants = cva(
}
)

export type ButtonProps = {
export interface ButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
VariantProps<typeof buttonVariants> {
asChild?: boolean
} & React.ButtonHTMLAttributes<HTMLButtonElement> &
VariantProps<typeof buttonVariants>
}

const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant, size, asChild = false, ...props }, ref) => {
Expand Down
6 changes: 3 additions & 3 deletions components/ui/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import type { ControllerProps, FieldPath, FieldValues } from "react-hook-form"

const Form = FormProvider

type FormFieldContextValue<
interface FormFieldContextValue<
TFieldValues extends FieldValues = FieldValues,
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>
> = {
> {
name: TName
}

Expand Down Expand Up @@ -58,7 +58,7 @@ const useFormField = () => {
}
}

type FormItemContextValue = {
interface FormItemContextValue {
id: string
}

Expand Down
3 changes: 1 addition & 2 deletions components/ui/toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ const ToastViewport = React.forwardRef<
))
ToastViewport.displayName = ToastPrimitives.Viewport.displayName

// eslint-disable-next-line tailwindcss/no-custom-classname
const toastVariants = cva(
"group pointer-events-auto relative flex w-full items-center justify-between space-x-4 overflow-hidden rounded-md border p-6 pr-8 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full",
{
variants: {
variant: {
default: "border bg-background text-foreground",
destructive:
"destructive group border-destructive bg-destructive text-destructive-foreground"
"group border-destructive bg-destructive text-destructive-foreground"
}
},
defaultVariants: {
Expand Down
2 changes: 1 addition & 1 deletion components/ui/use-toast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type Action =
toastId?: ToasterToast["id"]
}

type State = {
interface State {
toasts: ToasterToast[]
}

Expand Down
8 changes: 4 additions & 4 deletions lib/api-fns/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import type { NextRequest, NextResponse } from "next/server"
/**
* The API Error response
*/
export type ApiResponseError = {
export interface ApiResponseError {
ok: false
error: string
issues?: ZodIssue[]
}

export type ApiResponseSuccess<T> = {
export interface ApiResponseSuccess<T> {
ok: true
data: T
}
Expand All @@ -24,7 +24,7 @@ export type ApiResponse<T> = ApiResponseSuccess<T> | ApiResponseError
/**
*
*/
export type NextRequestContext<T> = {
export interface NextRequestContext<T> {
params: T
}

Expand All @@ -34,7 +34,7 @@ export type NextRequestContext<T> = {
*
* See: https://nextjs.org/docs/app/api-reference/file-conventions/route#context-optional
*/
export type NextRouteContext<T = undefined> = {
export interface NextRouteContext<T = undefined> {
params: T
}

Expand Down

1 comment on commit 311c81e

@vercel
Copy link

@vercel vercel bot commented on 311c81e Sep 4, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.