Skip to content

Commit

Permalink
styled.shouldForwardProp: require prop to be a string
Browse files Browse the repository at this point in the history
  • Loading branch information
srmagura committed May 21, 2022
1 parent 5e81f21 commit 5595c8d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/is-prop-valid/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Definitions by: Junyoung Clare Jang <https://github.com/Ailrun>
// TypeScript Version: 2.1

declare function isPropValid(string: PropertyKey): boolean
declare function isPropValid(prop: string): boolean
export default isPropValid
12 changes: 7 additions & 5 deletions packages/native/types/base.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ export type Interpolation<
/** Same as StyledOptions but shouldForwardProp must be a type guard */
export interface FilteringStyledOptions<
Props,
ForwardedProps extends keyof Props = keyof Props
ForwardedProps extends keyof Props & string = keyof Props & string
> {
shouldForwardProp?(propName: PropertyKey): propName is ForwardedProps
shouldForwardProp?(propName: string): propName is ForwardedProps
}

export interface StyledOptions<Props> {
shouldForwardProp?(propName: PropertyKey): boolean
shouldForwardProp?(propName: string): boolean
}

/**
Expand Down Expand Up @@ -146,7 +146,8 @@ export interface CreateStyledComponent<
export interface CreateStyled {
<
C extends React.ComponentClass<React.ComponentProps<C>>,
ForwardedProps extends keyof React.ComponentProps<C> = keyof React.ComponentProps<C>
ForwardedProps extends keyof React.ComponentProps<C> &
string = keyof React.ComponentProps<C> & string
>(
component: C,
options: FilteringStyledOptions<React.ComponentProps<C>, ForwardedProps>
Expand Down Expand Up @@ -175,7 +176,8 @@ export interface CreateStyled {

<
C extends React.ComponentType<React.ComponentProps<C>>,
ForwardedProps extends keyof React.ComponentProps<C> = keyof React.ComponentProps<C>
ForwardedProps extends keyof React.ComponentProps<C> &
string = keyof React.ComponentProps<C> & string
>(
component: C,
options: FilteringStyledOptions<React.ComponentProps<C>, ForwardedProps>
Expand Down
15 changes: 9 additions & 6 deletions packages/styled/types/base.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ export { ComponentSelector, Interpolation }
/** Same as StyledOptions but shouldForwardProp must be a type guard */
export interface FilteringStyledOptions<
Props,
ForwardedProps extends keyof Props = keyof Props
ForwardedProps extends keyof Props & string = keyof Props & string
> {
label?: string
shouldForwardProp?(propName: PropertyKey): propName is ForwardedProps
shouldForwardProp?(propName: string): propName is ForwardedProps
target?: string
}

export interface StyledOptions<Props> {
label?: string
shouldForwardProp?(propName: PropertyKey): boolean
shouldForwardProp?(propName: string): boolean
target?: string
}

Expand Down Expand Up @@ -118,7 +118,8 @@ export interface CreateStyledComponent<
export interface CreateStyled {
<
C extends React.ComponentClass<React.ComponentProps<C>>,
ForwardedProps extends keyof React.ComponentProps<C> = keyof React.ComponentProps<C>
ForwardedProps extends keyof React.ComponentProps<C> &
string = keyof React.ComponentProps<C> & string
>(
component: C,
options: FilteringStyledOptions<React.ComponentProps<C>, ForwardedProps>
Expand Down Expand Up @@ -147,7 +148,8 @@ export interface CreateStyled {

<
C extends React.ComponentType<React.ComponentProps<C>>,
ForwardedProps extends keyof React.ComponentProps<C> = keyof React.ComponentProps<C>
ForwardedProps extends keyof React.ComponentProps<C> &
string = keyof React.ComponentProps<C> & string
>(
component: C,
options: FilteringStyledOptions<React.ComponentProps<C>, ForwardedProps>
Expand All @@ -168,7 +170,8 @@ export interface CreateStyled {

<
Tag extends keyof JSX.IntrinsicElements,
ForwardedProps extends keyof JSX.IntrinsicElements[Tag] = keyof JSX.IntrinsicElements[Tag]
ForwardedProps extends keyof JSX.IntrinsicElements[Tag] &
string = keyof JSX.IntrinsicElements[Tag] & string
>(
tag: Tag,
options: FilteringStyledOptions<JSX.IntrinsicElements[Tag], ForwardedProps>
Expand Down

0 comments on commit 5595c8d

Please sign in to comment.