Skip to content

Commit 1c4feb7

Browse files
fix(react-jss/types): fix react default props types support (#1353)
Co-authored-by: Sergey Gavrilov <[email protected]>
1 parent bf455f5 commit 1c4feb7

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ Since you are interested in what happens next, in case, you work for a for-profi
44

55
---
66

7+
### Improvements
8+
9+
- [react-jss] add properly react default props types calculation (https://github.com/cssinjs/jss/pull/1353)
10+
711
## 10.3.0 (2020-6-10)
812

913
### Improvements

packages/react-jss/src/index.d.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,19 @@ declare function createUseStyles<Theme = DefaultTheme, C extends string = string
6666
options?: CreateUseStylesOptions<Theme>
6767
): (data?: unknown) => Classes<C>
6868

69+
type GetProps<C> = C extends ComponentType<infer P> ? P : never
70+
6971
declare function withStyles<
7072
ClassNames extends string | number | symbol,
7173
S extends Styles<ClassNames> | ((theme: any) => Styles<ClassNames>)
7274
>(
7375
styles: S,
7476
options?: WithStylesOptions
75-
): <
76-
Props extends {
77-
classes: S extends (theme: any) => Styles<ClassNames>
78-
? Classes<keyof ReturnType<S>>
79-
: Classes<ClassNames>
80-
}
81-
>(
82-
comp: ComponentType<Props>
83-
) => ComponentType<Omit<Props, 'classes'> & {classes?: Partial<Props['classes']>}>
77+
): <C>(
78+
comp: C
79+
) => ComponentType<
80+
JSX.LibraryManagedAttributes<C, Omit<GetProps<C>, 'classes'> & Partial<WithStylesProps<S>>>
81+
>
8482

8583
type Omit<T, K> = Pick<T, Exclude<keyof T, K>>
8684

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React, {Component} from 'react'
2+
3+
import WithStyles from '.'
4+
5+
interface Props {
6+
testProp: string
7+
}
8+
9+
class TestComponent extends Component<Props> {
10+
static defaultProps: Props = {
11+
testProp: 'hello'
12+
}
13+
14+
render() {
15+
return <div>{this.props.testProp}</div>
16+
}
17+
}
18+
19+
const TestComponentWitStyles = WithStyles({})(TestComponent)
20+
21+
function testRender() {
22+
// component shouldn't ask to pass `testProp`
23+
return <TestComponentWitStyles />
24+
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
"moduleResolution": "node",
1010
"jsx": "react"
1111
},
12-
"include": ["packages/**/*.ts"]
12+
"include": ["packages/**/*.ts", "packages/**/*.tsx"]
1313
}

0 commit comments

Comments
 (0)