-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreact-jsx.types.test-d.ts
More file actions
58 lines (48 loc) · 1.91 KB
/
react-jsx.types.test-d.ts
File metadata and controls
58 lines (48 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* This file is a type-only test suite: declarations are intentionally "unused"
* so TypeScript will fail the build if the reactJsx typings drift. Linting is
* secondary here, so we disable unused-var checks.
*/
/* eslint-disable @typescript-eslint/no-unused-vars */
import type * as React from 'react'
import type {
ReactJsxChildren,
ReactJsxComponent,
ReactJsxDomAttributes,
ReactJsxEventHandler,
ReactJsxIntrinsicElement,
ReactJsxIntrinsicElements,
ReactJsxRef,
ReactJsxRenderable,
} from '../src/react/index.js'
type Equal<A, B> =
(<T>() => T extends A ? 1 : 2) extends <T>() => T extends B ? 1 : 2 ? true : false
type Expect<T extends true> = T
type IntrinsicElementsEqual = Expect<
Equal<ReactJsxIntrinsicElements, React.JSX.IntrinsicElements>
>
type ButtonProps = ReactJsxIntrinsicElement<'button'>
type ButtonClick = Parameters<NonNullable<ButtonProps['onClick']>>[0]
type ButtonClickIsReactMouse = Expect<
Equal<ButtonClick, React.MouseEvent<HTMLButtonElement>>
>
type ButtonRefIsReactRef = Expect<
Equal<ButtonProps['ref'], ReactJsxRef<HTMLButtonElement> | undefined>
>
type DomAttributesMatch = Expect<
Equal<ReactJsxDomAttributes<HTMLDivElement>, React.DOMAttributes<HTMLDivElement>>
>
type EventHandlerType = ReactJsxEventHandler<React.SyntheticEvent<HTMLDivElement>>
const _eventHandler: EventHandlerType | undefined = undefined
// @ts-expect-error href is not allowed on button
const invalidButton: ButtonProps = { href: '#' }
type DemoProps = { label: string }
type DemoComponent = ReactJsxComponent<DemoProps>
type DemoComponentProps = React.ComponentProps<DemoComponent>
type DemoPropsArePropsWithChildren = Expect<
Equal<DemoComponentProps, React.PropsWithChildren<DemoProps>>
>
type RenderableAllowsNull = Expect<null extends ReactJsxRenderable ? true : false>
type ReactChildrenAliasMatchesRenderableUnion = Expect<
Equal<ReactJsxChildren, ReactJsxRenderable | ReactJsxRenderable[]>
>