Skip to content

Commit 5ced6b9

Browse files
committed
fix: types for [example].tsx
1 parent 49edc99 commit 5ced6b9

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

site/pages/examples/[example].tsx

+30-19
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ import CustomPlaceholder from '../../examples/ts/custom-placeholder'
3333
// node
3434
import { getAllExamples } from '../api'
3535

36-
const EXAMPLES = [
36+
type ExampleTuple = [string, React.ComponentType, string]
37+
38+
const EXAMPLES: ExampleTuple[] = [
3739
['Checklists', CheckLists, 'check-lists'],
3840
['Editable Voids', EditableVoids, 'editable-voids'],
3941
['Embeds', Embeds, 'embeds'],
@@ -58,7 +60,7 @@ const EXAMPLES = [
5860
['Custom placeholder', CustomPlaceholder, 'custom-placeholder'],
5961
]
6062

61-
const Header = props => (
63+
const Header = (props: React.HTMLAttributes<HTMLDivElement>) => (
6264
<div
6365
{...props}
6466
className={css`
@@ -73,7 +75,7 @@ const Header = props => (
7375
/>
7476
)
7577

76-
const Title = props => (
78+
const Title = (props: React.HTMLAttributes<HTMLSpanElement>) => (
7779
<span
7880
{...props}
7981
className={css`
@@ -82,7 +84,7 @@ const Title = props => (
8284
/>
8385
)
8486

85-
const LinkList = props => (
87+
const LinkList = (props: React.HTMLAttributes<HTMLDivElement>) => (
8688
<div
8789
{...props}
8890
className={css`
@@ -92,7 +94,7 @@ const LinkList = props => (
9294
/>
9395
)
9496

95-
const A = props => (
97+
const A = (props: React.AnchorHTMLAttributes<HTMLAnchorElement>) => (
9698
<a
9799
{...props}
98100
className={css`
@@ -108,7 +110,7 @@ const A = props => (
108110
/>
109111
)
110112

111-
const Pill = props => (
113+
const Pill = (props: React.HTMLAttributes<HTMLSpanElement>) => (
112114
<span
113115
{...props}
114116
className={css`
@@ -120,7 +122,10 @@ const Pill = props => (
120122
/>
121123
)
122124

123-
const TabList = ({ isVisible, ...props }) => (
125+
const TabList = ({
126+
isVisible,
127+
...props
128+
}: React.HTMLAttributes<HTMLDivElement> & { isVisible?: boolean }) => (
124129
<div
125130
{...props}
126131
className={css`
@@ -139,7 +144,10 @@ const TabList = ({ isVisible, ...props }) => (
139144
/>
140145
)
141146

142-
const TabListUnderlay = ({ isVisible, ...props }) => (
147+
const TabListUnderlay = ({
148+
isVisible,
149+
...props
150+
}: React.HTMLAttributes<HTMLDivElement> & { isVisible?: boolean }) => (
143151
<div
144152
{...props}
145153
className={css`
@@ -153,7 +161,7 @@ const TabListUnderlay = ({ isVisible, ...props }) => (
153161
/>
154162
)
155163

156-
const TabButton = props => (
164+
const TabButton = (props: React.HTMLAttributes<HTMLSpanElement>) => (
157165
<span
158166
{...props}
159167
className={css`
@@ -182,7 +190,7 @@ const Tab = React.forwardRef(
182190
href: string
183191
[key: string]: unknown
184192
}>,
185-
ref: Ref<HTMLAnchorElement | null>
193+
ref: Ref<HTMLAnchorElement>
186194
) => (
187195
<a
188196
ref={ref}
@@ -205,7 +213,10 @@ const Tab = React.forwardRef(
205213
)
206214
)
207215

208-
const Wrapper = ({ className, ...props }) => (
216+
const Wrapper = ({
217+
className,
218+
...props
219+
}: React.HTMLAttributes<HTMLDivElement>) => (
209220
<div
210221
{...props}
211222
className={cx(
@@ -219,7 +230,7 @@ const Wrapper = ({ className, ...props }) => (
219230
/>
220231
)
221232

222-
const ExampleHeader = props => (
233+
const ExampleHeader = (props: React.HTMLAttributes<HTMLDivElement>) => (
223234
<div
224235
{...props}
225236
className={css`
@@ -234,7 +245,7 @@ const ExampleHeader = props => (
234245
/>
235246
)
236247

237-
const ExampleTitle = props => (
248+
const ExampleTitle = (props: React.HTMLAttributes<HTMLSpanElement>) => (
238249
<span
239250
{...props}
240251
className={css`
@@ -243,7 +254,7 @@ const ExampleTitle = props => (
243254
/>
244255
)
245256

246-
const ExampleContent = props => (
257+
const ExampleContent = (props: React.HTMLAttributes<HTMLDivElement>) => (
247258
<Wrapper
248259
{...props}
249260
className={css`
@@ -252,7 +263,7 @@ const ExampleContent = props => (
252263
/>
253264
)
254265

255-
const Warning = props => (
266+
const Warning = (props: React.HTMLAttributes<HTMLDivElement>) => (
256267
<Wrapper
257268
{...props}
258269
className={css`
@@ -269,11 +280,11 @@ const Warning = props => (
269280
)
270281

271282
const ExamplePage = ({ example }: { example: string }) => {
272-
const [error, setError] = useState<Error | undefined>()
273-
const [stacktrace, setStacktrace] = useState<ErrorInfo | undefined>()
274-
const [showTabs, setShowTabs] = useState<boolean>()
283+
const [error, setError] = useState<Error | undefined>(undefined)
284+
const [stacktrace, setStacktrace] = useState<ErrorInfo | undefined>(undefined)
285+
const [showTabs, setShowTabs] = useState<boolean>(false)
275286
const EXAMPLE = EXAMPLES.find(e => e[2] === example)
276-
const [name, Component, path] = EXAMPLE
287+
const [name, Component, path] = EXAMPLE!
277288
return (
278289
<ErrorBoundary
279290
onError={(error, stacktrace) => {

0 commit comments

Comments
 (0)