Skip to content
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
4 changes: 2 additions & 2 deletions contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ yarn build
To lint, format, and type check the project run the following commands:

```bash
yarn lint
yarn check:lint
yarn format
yarn typecheck
yarn check:ts
```

## Run tests
Expand Down
9 changes: 8 additions & 1 deletion packages/react-jss/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,14 @@ interface WithStylesProps<S extends Styles | ((theme: any) => Styles)> {
*/
type WithStyles<S extends Styles | ((theme: any) => Styles)> = WithStylesProps<S>

export interface DefaultTheme {}
declare global {
namespace Jss {
/** You can use the global `Jss.Theme` interface to define a project-wide default theme. */
export interface Theme {}
}
}

export type DefaultTheme = Jss.Theme

interface BaseOptions<Theme = DefaultTheme> extends StyleSheetFactoryOptions {
index?: number
Expand Down
39 changes: 38 additions & 1 deletion packages/react-jss/src/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react'
import WithStyles, {createUseStyles} from '.'

import WithStyles from '.'
const expectType = <T extends any>(x: T): T => x

interface Props {
testProp: string
Expand Down Expand Up @@ -43,3 +44,39 @@ function testRender() {
</>
)
}

declare global {
namespace Jss {
export interface Theme {
themeColour: string
defaultFontSize: number
}
}
}

const useStyles = createUseStyles(theme => {
expectType<string>(theme.themeColour)
expectType<number>(theme.defaultFontSize)

return {
myDiv: {
color: theme.themeColour,
// @ts-expect-error typescript should error here since the theme property doesn't exist
border: theme.aPropertyThatDoesntExist
}
}
})

export function Component() {
const classes = useStyles()

expectType<string>(classes.myDiv)

return (
<>
<div className={classes.myDiv} />
{/* @ts-expect-error typescript should error here since the class is invalid */}
<div className={classes.thisClassDoesntExist} />
</>
)
}