Skip to content

Commit

Permalink
feat: fix typings for functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jpudysz committed Oct 6, 2023
1 parent 40c1662 commit cad552e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
3 changes: 2 additions & 1 deletion example/src/examples/Extreme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ const stylesheet = createStyles(theme => ({
},
{
translateX: {
sm: 10
sm: 10,
md: 20
}
}
]
Expand Down
6 changes: 5 additions & 1 deletion example/src/examples/MinimalWithCreateStyles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ const stylesheet = createStyles({
text: {
borderWidth: 1,
borderColor: 'purple',
padding: 20
padding: 20,
flex: {
xs: 2,
md: 1
}
}
})
8 changes: 7 additions & 1 deletion src/createUnistyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ export const createUnistyles = <B extends Record<string, number>, T = {}>(breakp
const sortedBreakpoints = sortAndValidateBreakpoints(breakpoints)

return {
createStyles: <S extends CustomNamedStyles<S, B>>(styles: S | CustomNamedStyles<S, B> | CreateStylesFactory<S, T>) => styles as S,
createStyles: <S extends CustomNamedStyles<S, B>, X>(styles: S | CustomNamedStyles<S, B> | X | ((theme: T) => X | CustomNamedStyles<X, B>)): S | X => {
if (typeof styles === 'function') {
return styles as X
}

return styles as S
},
useStyles: <ST extends CustomNamedStyles<ST, B>>(stylesheet?: ST | CreateStylesFactory<ST, T>) => {
const theme = useContext(UnistylesContext) as T
const dimensions = useDimensions()
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type ScreenSize = {
height: number
}

export type CreateStylesFactory<T, Theme> = (theme: Theme) => T
export type CreateStylesFactory<ST, Theme> = (theme: Theme) => ST

type StyleProperty<T, B extends Record<string, number>> = {
[K in keyof T]: {
Expand Down

0 comments on commit cad552e

Please sign in to comment.