I'm currently translating my style solution based on jss to typescript and I've stumble in the following situation.
Consider my basic setup
import { useStyles } from './styles'
const styles = theme =>({
root : { color: 'white' },
foo : { backgroundColor: 'red' },
})
const Component = () =>{
const classes = useStyles(styles)
return <div className={classes.root} />
}
You pass a style's object to useStyles and the returned value is an object which contains all keys declared inside styles. So my classes object looks like this
{
root : 'random-name123',
foo : 'random-name124'
}
Since I can't possibly know which keys styles will have, my current interface for classes is just a dictionary
interface Classes {
[index: string]: string
}
My question is:
Can I declare an interface in such a way that all keys passed to styles are declared as being part of Classes? So that when I type classes. I would be able to see all possible keys for classes?
In other words, I want the keys which compose Classes to be predictable. So that if I pass a styles objects like this
{
foo : {/*...*/},
bar: {/*...*/}
}
My Classes interface would look like
{
foo : string,
bar : string
}