File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,9 +26,9 @@ yarn build
2626To lint, format, and type check the project run the following commands:
2727
2828``` bash
29- yarn lint
29+ yarn check: lint
3030yarn format
31- yarn typecheck
31+ yarn check:ts
3232```
3333
3434## Run tests
Original file line number Diff line number Diff line change @@ -45,7 +45,14 @@ interface WithStylesProps<S extends Styles | ((theme: any) => Styles)> {
4545 */
4646type WithStyles < S extends Styles | ( ( theme : any ) => Styles ) > = WithStylesProps < S >
4747
48- export interface DefaultTheme { }
48+ declare global {
49+ namespace Jss {
50+ /** You can use the global `Jss.Theme` interface to define a project-wide default theme. */
51+ export interface Theme { }
52+ }
53+ }
54+
55+ export type DefaultTheme = Jss . Theme
4956
5057interface BaseOptions < Theme = DefaultTheme > extends StyleSheetFactoryOptions {
5158 index ?: number
Original file line number Diff line number Diff line change 11import * as React from 'react'
2+ import WithStyles , { createUseStyles } from '.'
23
3- import WithStyles from '.'
4+ const expectType = < T extends any > ( x : T ) : T => x
45
56interface Props {
67 testProp : string
@@ -43,3 +44,39 @@ function testRender() {
4344 </ >
4445 )
4546}
47+
48+ declare global {
49+ namespace Jss {
50+ export interface Theme {
51+ themeColour : string
52+ defaultFontSize : number
53+ }
54+ }
55+ }
56+
57+ const useStyles = createUseStyles ( theme => {
58+ expectType < string > ( theme . themeColour )
59+ expectType < number > ( theme . defaultFontSize )
60+
61+ return {
62+ myDiv : {
63+ color : theme . themeColour ,
64+ // @ts -expect-error typescript should error here since the theme property doesn't exist
65+ border : theme . aPropertyThatDoesntExist
66+ }
67+ }
68+ } )
69+
70+ export function Component ( ) {
71+ const classes = useStyles ( )
72+
73+ expectType < string > ( classes . myDiv )
74+
75+ return (
76+ < >
77+ < div className = { classes . myDiv } />
78+ { /* @ts -expect-error typescript should error here since the class is invalid */ }
79+ < div className = { classes . thisClassDoesntExist } />
80+ </ >
81+ )
82+ }
You can’t perform that action at this time.
0 commit comments