Consider our types,
type Types = 'a' | 'b'
and our container:
interface Container<T extends Types> {
p: T,
q: T,
}
Now here are two ways of declaring an array of these containers. My issue is that I have not clean a method of writing the first (good?) array without writing out all possible container types.
Some help would be greatly appreciated, or any insights into a better way of doing this all together :)
const goodArr: (Container<'a'> | Container<'b'>)[] = [
{
p: 'a',
q: 'a',
},
{
p: 'b',
q: 'a', // compiler doesn't allow this
},
];
const badArr: Container<Types>[] = [
{
p: 'a',
q: 'a',
},
{
p: 'b',
q: 'a', // compiler allows this
},
];