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

fix exported types #239

Merged
merged 3 commits into from
Sep 15, 2022
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
62 changes: 61 additions & 1 deletion examples/example/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ import {
// Import from core
import { H4 } from '@dripsy/core'
import { Gradient } from '@dripsy/gradient'
import { Text, TextInput, View as NativeView } from 'react-native'
import {
Text,
TextInput,
View as NativeView,
KeyboardAvoidingView,
} from 'react-native'

const theme = makeTheme({
colors: {
Expand Down Expand Up @@ -137,6 +142,61 @@ export type TestElement = MyViewElement extends never ? never : 'ok'
// should not have TS errors because element type should not be never ✅
export const testElement: { el: TestElement } = { el: 'ok' }

export const ExtendedComp = styled(KeyboardAvoidingView)({})

export const ExtendedCompWithExtraProps = styled<
React.ComponentProps<typeof KeyboardAvoidingView> & { custom?: boolean }
>(KeyboardAvoidingView)({})

export const ExtendedCompWithExtraProps2 = styled(KeyboardAvoidingView)<
React.ComponentProps<typeof KeyboardAvoidingView> & { custom?: boolean }
>({})

export const ExtendA = () => (
<ExtendedComp
/* @ts-expect-error behavior cannot be 'test' */
behavior="test"
/>
)
/* should not error */
export const ExtendB = () => <ExtendedComp behavior="padding" />
export const ExtendC = () => (
<ExtendedComp
/* @ts-expect-error custom does not exist */
custom="test"
/>
)
export const ExtendE = () => (
<ExtendedCompWithExtraProps
/* @ts-expect-error behavior cannot be 'test' */
behavior="test"
/>
)
/* should not error */
export const ExtendF = () => <ExtendedCompWithExtraProps behavior="padding" />
export const ExtendG = () => (
<ExtendedCompWithExtraProps
/* @ts-expect-error custom cannot be string */
custom="test"
/>
)
/* should not error */
export const ExtendH = () => <ExtendedCompWithExtraProps custom={false} />
export const ExtendI = () => <ExtendedCompWithExtraProps2 behavior="test" />

/* should not error */
export const ExtendJ = () => <ExtendedCompWithExtraProps2 behavior="padding" />

export const ExtendK = () => (
<ExtendedCompWithExtraProps2
/* @ts-expect-error custom cannot be string */
custom="test"
/>
)

/* should not error */
export const ExtendL = () => <ExtendedCompWithExtraProps2 custom={false} />

const ResponsiveSquare = () => {
// Return literal values:
const textColor = useResponsiveValue(['red', 'green', 'blue'])
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/css/create-themed-component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type PropsWithStyledProps<P, ThemeKey extends keyof DripsyFinalTheme> = P &
StyledProps<ThemeKey>

// prettier-ignore
type Props<C, ExtraProps, ThemeKey extends keyof DripsyFinalTheme> = C extends ComponentType<infer BaseProps>
export type Props<C, ExtraProps, ThemeKey extends keyof DripsyFinalTheme> = C extends ComponentType<infer BaseProps>
? MergeProps<PropsWithoutVariants<BaseProps>, PropsWithStyledProps<ExtraProps, ThemeKey>>
: never

Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/css/styled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import type { ThemedOptions } from './types'
* ```
*
*/

export function styled<
C extends ComponentType<any>,
Props,
C extends ComponentType<any> = ComponentType<Props>,
ThemeKey extends keyof DripsyFinalTheme = keyof DripsyFinalTheme
>(
Component: C,
Expand Down