I don't know if I'm searching well, but I'd like to do something like a conditional type. I would like to transform this type in my project:
type CommonProps = {
duration: number;
type?: 'primary' | 'secondary';
variant?: 'linear' | 'circular' | 'square'
}
It should work on a principles: If a primary type has been selected, variant is available: 'linear' | 'circular' | 'square' but if secondary type has been selected, variant is available: 'linear' | 'circular'.
I tried to transform it to:
type CommonProps = {
duration: number;
}& {
type?: 'primary'
variant?: 'linear' | 'circular' | 'square'
} & {
type?: 'secondary';
variant?: 'linear' | 'circular'
}
Unfortunately, this does not meet expectations as there is a problem with this use later in the code for example: styles[type][variant];.