Skip to content

Commit

Permalink
chore: snap emotion-js#2
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Mar 9, 2022
1 parent d3092bb commit 946d38f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
4 changes: 4 additions & 0 deletions packages/native/types/tsconfig.json
Expand Up @@ -6,6 +6,10 @@
"lib": ["es6", "dom"],
"module": "commonjs",
"noEmit": true,
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strict": true,
"target": "es5",
"typeRoots": ["../"],
Expand Down
20 changes: 16 additions & 4 deletions packages/styled/types/base.d.ts
Expand Up @@ -22,20 +22,32 @@ export { ComponentSelector, Interpolation }
* Practical sense: you can define and reuse atomic `shouldForwardProp` filters that are strictly bound with some `ForwardedProps` type.
*/
export interface FilteringStyledOptions<
Props = Record<PropertyKey, any>,
Props = AnyRecord,
ForwardedProps extends keyof Props = keyof Props
> {
label?: string
shouldForwardProp?(propName: PropertyKey): propName is ForwardedProps
shouldForwardProp?: <P extends UnionToIntersection<ForwardedProps>>(
propName: P
) => propName is P
target?: string
}

export interface StyledOptions<Props = Record<PropertyKey, any>> {
export interface StyledOptions<Props = AnyRecord> {
label?: string
shouldForwardProp?(propName: keyof Props): boolean
shouldForwardProp?: <P extends keyof UnionToIntersection<Props>>(
propName: P
) => boolean
target?: string
}

type AnyRecord = Record<PropertyKey, any>

export type UnionToIntersection<U, K = any> = (
U extends K ? (k: U) => void : never
) extends (k: infer I) => void
? I
: never

/**
* @typeparam ComponentProps Props which will be included when withComponent is called
* @typeparam SpecificComponentProps Props which will *not* be included when withComponent is called
Expand Down
10 changes: 5 additions & 5 deletions packages/styled/types/tests.tsx
Expand Up @@ -274,11 +274,11 @@ const Input5 = styled.input`
'foo'
>['shouldForwardProp'] = (prop: 'foo' | 'bar'): prop is 'bar' => true

styled('div', { shouldForwardProp: (prop: 'color') => true })({})

styled('div', {
shouldForwardProp: (prop: 'color'): prop is 'color' => true
})({})
// styled('div', { shouldForwardProp: (prop: 'color') => true })({})
//
// styled('div', {
// shouldForwardProp: (prop: 'style'): prop is 'style' => true
// })({})

// $ExpectError
styled('div', { shouldForwardProp: (prop: 'foo') => true })({})
Expand Down
4 changes: 4 additions & 0 deletions packages/styled/types/tsconfig.json
Expand Up @@ -7,6 +7,10 @@
"lib": ["es6", "dom"],
"module": "commonjs",
"noEmit": true,
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strict": true,
"target": "es5",
"typeRoots": ["../"],
Expand Down

0 comments on commit 946d38f

Please sign in to comment.