We (that is @mattwagl, @yeldiRium and me) have recently migrated our module's dependencies jss and react-jss to 10.0.0, and have tried to convert from the HOC approach withStyles function to the hook-based approach with createUseStyles.
Since we are using theming, we would like to use createUseStyles with a function parameter, basically like this:
const useStyles = createUseStyles(theme => ({
// ...
}));
Problems start when we look at the types of the useStyles function.
Expected behavior:
What we expect is that useStyles should return something of type Styles, or at least something such as Record<string, string>.
Actual behavior:
What it actually returns is Record<never, string>. We don't know where this never comes from, but obviously this is not what it should be 😉
Workaround
We are able to fix this by using
const useStyles = createUseStyles<string>(theme => ({
// ...
}));
but this for sure can't be the right way to go. Actually, it even makes us wonder that this works, since createUseStyles takes two type parameters when providing a function. Something with the typings seems to be broken here (or we missed something very essential with respect to this new hook-based approach).
System environment
- Node.js 12.10.0
- macOS 10.14.6 (Mojave)
We (that is @mattwagl, @yeldiRium and me) have recently migrated our module's dependencies
jssandreact-jssto10.0.0, and have tried to convert from the HOC approachwithStylesfunction to the hook-based approach withcreateUseStyles.Since we are using theming, we would like to use
createUseStyleswith a function parameter, basically like this:Problems start when we look at the types of the
useStylesfunction.Expected behavior:
What we expect is that
useStylesshould return something of typeStyles, or at least something such asRecord<string, string>.Actual behavior:
What it actually returns is
Record<never, string>. We don't know where thisnevercomes from, but obviously this is not what it should be 😉Workaround
We are able to fix this by using
but this for sure can't be the right way to go. Actually, it even makes us wonder that this works, since
createUseStylestakes two type parameters when providing a function. Something with the typings seems to be broken here (or we missed something very essential with respect to this new hook-based approach).System environment