Skip to content

Commit

Permalink
Remove everything besides ReactJSXIntrinsicElements from packages/sty…
Browse files Browse the repository at this point in the history
…led/types/jsx-namespace.d.ts since it's the only thing that's used
  • Loading branch information
emmatown committed Jul 18, 2024
1 parent 0505dac commit 8c602ad
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 75 deletions.
22 changes: 11 additions & 11 deletions packages/styled/types/base.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import * as React from 'react'
import { ComponentSelector, Interpolation } from '@emotion/serialize'
import { PropsOf, Theme } from '@emotion/react'
import { ReactJSX } from './jsx-namespace'
import { ReactJSXIntrinsicElements } from './jsx-namespace'

export {
ArrayInterpolation,
Expand Down Expand Up @@ -50,9 +50,9 @@ export interface StyledComponent<
withComponent<C extends React.ComponentType<React.ComponentProps<C>>>(
component: C
): StyledComponent<ComponentProps & PropsOf<C>>
withComponent<Tag extends keyof ReactJSX.IntrinsicElements>(
withComponent<Tag extends keyof ReactJSXIntrinsicElements>(
tag: Tag
): StyledComponent<ComponentProps, ReactJSX.IntrinsicElements[Tag]>
): StyledComponent<ComponentProps, ReactJSXIntrinsicElements[Tag]>
}

/**
Expand Down Expand Up @@ -170,26 +170,26 @@ export interface CreateStyled {
>

<
Tag extends keyof ReactJSX.IntrinsicElements,
ForwardedProps extends keyof ReactJSX.IntrinsicElements[Tag] &
string = keyof ReactJSX.IntrinsicElements[Tag] & string
Tag extends keyof ReactJSXIntrinsicElements,
ForwardedProps extends keyof ReactJSXIntrinsicElements[Tag] &
string = keyof ReactJSXIntrinsicElements[Tag] & string
>(
tag: Tag,
options: FilteringStyledOptions<
ReactJSX.IntrinsicElements[Tag],
ReactJSXIntrinsicElements[Tag],
ForwardedProps
>
): CreateStyledComponent<
{ theme?: Theme; as?: React.ElementType },
Pick<ReactJSX.IntrinsicElements[Tag], ForwardedProps>
Pick<ReactJSXIntrinsicElements[Tag], ForwardedProps>
>

<Tag extends keyof ReactJSX.IntrinsicElements>(
<Tag extends keyof ReactJSXIntrinsicElements>(
tag: Tag,
options?: StyledOptions<ReactJSX.IntrinsicElements[Tag]>
options?: StyledOptions<ReactJSXIntrinsicElements[Tag]>
): CreateStyledComponent<
{ theme?: Theme; as?: React.ElementType },
ReactJSX.IntrinsicElements[Tag]
ReactJSXIntrinsicElements[Tag]
>
}

Expand Down
6 changes: 3 additions & 3 deletions packages/styled/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { Theme } from '@emotion/react'
import { CreateStyled as BaseCreateStyled, CreateStyledComponent } from './base'
import { ReactJSX } from './jsx-namespace'
import { ReactJSXIntrinsicElements } from './jsx-namespace'

export {
ArrayInterpolation,
Expand All @@ -18,12 +18,12 @@ export {
} from './base'

export type StyledTags = {
[Tag in keyof ReactJSX.IntrinsicElements]: CreateStyledComponent<
[Tag in keyof ReactJSXIntrinsicElements]: CreateStyledComponent<
{
theme?: Theme
as?: React.ElementType
},
ReactJSX.IntrinsicElements[Tag]
ReactJSXIntrinsicElements[Tag]
>
}

Expand Down
62 changes: 1 addition & 61 deletions packages/styled/types/jsx-namespace.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,68 +7,8 @@ type IsPreReact19 = 2 extends Parameters<React.FunctionComponent<any>>['length']
? true
: false

// unpack all here to avoid infinite self-referencing when defining our own JSX namespace for the pre-React 19 case
type ReactJSXElement = true extends IsPreReact19
? /** @ts-ignore */
JSX.Element
: /** @ts-ignore */
React.JSX.Element
type ReactJSXElementClass = true extends IsPreReact19
? /** @ts-ignore */
JSX.ElementClass
: /** @ts-ignore */
React.JSX.ElementClass
type ReactJSXElementAttributesProperty = true extends IsPreReact19
? /** @ts-ignore */
JSX.ElementAttributesProperty
: /** @ts-ignore */
React.JSX.ElementAttributesProperty
type ReactJSXElementChildrenAttribute = true extends IsPreReact19
? /** @ts-ignore */
JSX.ElementChildrenAttribute
: /** @ts-ignore */
React.JSX.ElementChildrenAttribute
type ReactJSXLibraryManagedAttributes<C, P> = true extends IsPreReact19
? /** @ts-ignore */
JSX.LibraryManagedAttributes<C, P>
: /** @ts-ignore */
React.JSX.LibraryManagedAttributes<C, P>
type ReactJSXIntrinsicAttributes = true extends IsPreReact19
? /** @ts-ignore */
JSX.IntrinsicAttributes
: /** @ts-ignore */
React.JSX.IntrinsicAttributes
type ReactJSXIntrinsicClassAttributes<T> = true extends IsPreReact19
? /** @ts-ignore */
JSX.IntrinsicClassAttributes<T>
: /** @ts-ignore */
React.JSX.IntrinsicClassAttributes<T>
type ReactJSXIntrinsicElements = true extends IsPreReact19
export type ReactJSXIntrinsicElements = true extends IsPreReact19
? /** @ts-ignore */
JSX.IntrinsicElements
: /** @ts-ignore */
React.JSX.IntrinsicElements

type ReactJSXElementType = true extends IsPreReact19
? // based on the code from @types/react@18.2.8
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/3197efc097d522c4bf02b94e1a0766d007d6cdeb/types/react/index.d.ts#LL3204C13-L3204C13
string | React.JSXElementConstructor<any>
: /** @ts-ignore */
React.JSX.ElementType

export namespace ReactJSX {
type ElementType = ReactJSXElementType
interface Element extends ReactJSXElement {}
interface ElementClass extends ReactJSXElementClass {}
interface ElementAttributesProperty
extends ReactJSXElementAttributesProperty {}
interface ElementChildrenAttribute extends ReactJSXElementChildrenAttribute {}

type LibraryManagedAttributes<C, P> = ReactJSXLibraryManagedAttributes<C, P>

interface IntrinsicAttributes extends ReactJSXIntrinsicAttributes {}
interface IntrinsicClassAttributes<T>
extends ReactJSXIntrinsicClassAttributes<T> {}

type IntrinsicElements = ReactJSXIntrinsicElements
}

0 comments on commit 8c602ad

Please sign in to comment.