Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'as' prop to types #846

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ComponentType } from 'react'
import { ComponentType, ElementType } from 'react'
import { Config as TailwindConfig } from 'tailwindcss'

export interface TwStyle {
Expand Down Expand Up @@ -26,7 +26,7 @@ export type ScreenFn = <T = string>(
) => (styles?: string | TemplateStringsArray | TwStyle | TwStyle[]) => T

export type TwComponent<K extends keyof JSX.IntrinsicElements> = (
props: JSX.IntrinsicElements[K]
props: JSX.IntrinsicElements[K] & { as?: ElementType }
) => JSX.Element

export type TwComponentMap = {
Expand Down
4 changes: 4 additions & 0 deletions types/tests/basic/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ const twProperty = (
)

const csProperty = <div cs="maxWidth[100%] height[calc(100vh - 1em)]" />
const asProperty = <Button as="div" />

// @ts-expect-error basic element doesn't provide as prop
const asPropertyError = <p as="div" />
3 changes: 3 additions & 0 deletions types/tests/emotion/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ export const ComposedLink2 = styled(Link)``

export const cssProperty = <div css={tw`bg-red-100`} />
export const csProperty = <div cs="maxWidth[100%] height[calc(100vh - 1em)]" />

export const asProperty = <Link as="button" />
export const asProperty2 = <Container as="button" />
3 changes: 3 additions & 0 deletions types/tests/styled-components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ export const ComposedLink2 = styled(Link)``

export const cssProperty = <div css={tw`bg-red-100`} />
export const csProperty = <div cs="maxWidth[100%] height[calc(100vh - 1em)]" />

export const asProperty = <Link as="button" />
export const asProperty2 = <Container as="button" />