I am currently trying to map an API response where some properties only exist if the parameters were passed.
To do this, I tried this bit of code:
interface FooDetails {
id: string;
}
interface FooImage {
url: string;
}
interface Foo<Params extends 'details' | 'image'> {
someProp: string;
details: Params extends 'details' ? FooDetails : undefined;
image: Params extends 'image' ? FooImage : undefined;
}
This technically works as it will only suggest undefined when attempting to access Foo<'details'>#image.
Can I rewrite this to throw a typescript error instead?