Skip to content

Commit 6711c86

Browse files
committed
🏷️ Replace any types with generics
1 parent 3dad687 commit 6711c86

69 files changed

Lines changed: 247 additions & 248 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

scripts/buildTypes.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,26 @@ import { utilityTypes } from './utilityTypes.js'
55
import fs from 'fs'
66

77
const componentsWithGenericTypes = [
8+
'Alert',
9+
'Badge',
10+
'Button',
11+
'Card',
12+
'Checkbox',
13+
'ConditionalWrapper',
14+
'ContextMenu',
15+
'Copy',
16+
'Counter',
17+
'Flex',
18+
'Grid',
819
'Image',
9-
'Modal'
20+
'Input',
21+
'Modal',
22+
'OTPInput',
23+
'Popover',
24+
'Radio',
25+
'Switch',
26+
'Textarea',
27+
'Toast'
1028
]
1129

1230
const componentsWithoutFrameworkSpecificTypes = [

src/components/Alert/Alert.astro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
2+
import type { HTMLAttributes } from 'astro/types'
23
import type { AlertProps } from './alert'
34
45
import ConditionalWrapper from '../ConditionalWrapper/ConditionalWrapper.astro'
@@ -10,7 +11,7 @@ import warning from '../../icons/warning.svg?raw'
1011
1112
import styles from './alert.module.scss'
1213
13-
interface Props extends AlertProps {}
14+
export type Props = AlertProps<HTMLAttributes<'section'>>
1415
1516
const iconMap = {
1617
info,

src/components/Alert/Alert.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script lang="ts">
22
import type { Snippet } from 'svelte'
3+
import type { HTMLAttributes } from 'svelte/elements'
34
import type { AlertProps } from './alert'
45
56
import ConditionalWrapper from '../ConditionalWrapper/ConditionalWrapper.svelte'
@@ -14,7 +15,7 @@
1415
export type SvelteAlertProps = {
1516
icon?: Snippet
1617
children: Snippet
17-
} & AlertProps
18+
} & AlertProps<HTMLAttributes<HTMLElement>>
1819
1920
const {
2021
element = 'section',

src/components/Alert/alert.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export type AlertProps = {
1+
export type AlertProps<T extends object = object> = {
22
element?: string
33
title?: string
44
titleTag?: string
@@ -9,5 +9,4 @@ export type AlertProps = {
99
| 'success'
1010
| 'warning'
1111
| 'alert'
12-
[key: string]: any
13-
}
12+
} & T

src/components/Badge/Badge.astro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
---
2+
import type { HTMLAttributes } from 'astro/types'
23
import type { BadgeProps } from './badge'
34
45
import styles from './badge.module.scss'
56
6-
interface Props extends BadgeProps {}
7+
export type Props = BadgeProps<HTMLAttributes<'span'>>
78
89
const {
910
theme,

src/components/Badge/Badge.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts">
22
import type { Snippet } from 'svelte'
3-
import type { MouseEventHandler } from 'svelte/elements'
3+
import type { HTMLAttributes, MouseEventHandler } from 'svelte/elements'
44
import type { BadgeProps } from './badge'
55
66
import { classNames } from '../../utils/classNames'
@@ -10,7 +10,7 @@
1010
export type SvelteBadgeProps = {
1111
onClick?: MouseEventHandler<HTMLButtonElement> | null
1212
children?: Snippet
13-
} & BadgeProps
13+
} & BadgeProps<HTMLAttributes<HTMLElement>>
1414
1515
const {
1616
theme,

src/components/Badge/Badge.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type React from 'react'
12
import type { BadgeProps } from './badge'
23

34
import { classNames } from '../../utils/classNames'
@@ -7,7 +8,7 @@ import styles from './badge.module.scss'
78
export type ReactBadgeProps = {
89
onClick?: React.MouseEventHandler<HTMLButtonElement>
910
children?: React.ReactNode
10-
} & BadgeProps
11+
} & BadgeProps<React.HTMLAttributes<HTMLElement>>
1112

1213
const Badge = ({
1314
theme,

src/components/Badge/badge.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export type BadgeProps = {
1+
type BadgeBase = {
22
theme?: 'secondary'
33
| 'outline'
44
| 'flat'
@@ -11,5 +11,16 @@ export type BadgeProps = {
1111
rounded?: boolean
1212
transparent?: boolean
1313
className?: string
14-
[key: string]: any
1514
}
15+
16+
type AsSpan<T extends object = object> = BadgeBase & {
17+
onClick?: never
18+
} & T
19+
20+
type AsButton<T extends object = object> = BadgeBase & {
21+
onClick: any
22+
} & T
23+
24+
export type BadgeProps<T extends object = object> =
25+
| AsSpan<T>
26+
| AsButton<T>

src/components/Button/Button.astro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
---
2+
import type { HTMLAttributes } from 'astro/types'
23
import type { ButtonProps } from './button'
34
45
import styles from './button.module.scss'
56
6-
interface Props extends ButtonProps {}
7+
export type Props = ButtonProps<HTMLAttributes<'button'>>
78
89
const {
910
theme,

src/components/Button/Button.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts">
22
import type { Snippet } from 'svelte'
3-
import type { MouseEventHandler } from 'svelte/elements'
3+
import type { HTMLAttributes, MouseEventHandler } from 'svelte/elements'
44
import type { ButtonProps } from './button'
55
66
import { classNames } from '../../utils/classNames'
@@ -10,7 +10,7 @@
1010
export type SvelteButtonProps = {
1111
onClick?: MouseEventHandler<HTMLButtonElement>
1212
children: Snippet
13-
} & ButtonProps
13+
} & ButtonProps<HTMLAttributes<HTMLElement>>
1414
1515
const {
1616
theme,

0 commit comments

Comments
 (0)