I'm having trouble grasping the concept of Advanced Types in Typescript.
I'm looking to create a type that includes both mandatory and optional properties, with the properties easily identifiable in a list.
Currently, I have a type for required properties and another type for optional properties.
type BaseProperties =
| 'price'
| 'cost'
| 'location';
type Features =
| 'radio'
| 'wings'
| 'tires'
| 'rockets'
| 'slushie_machine';
The desired type I want to achieve is:
type WithFeatures = {
price: string;
cost: string;
location: string;
radio?: string | number;
wings?: string | number;
tires?: string | number;
rockets?: string | number;
slushie_machine?: string | number;
};
Additionally, I want an array of:
public ThingsWithFeatures: WithFeatures[] = [];
I attempted to use:
type WithFeatures = Required<BaseProperties> & Partial<Features>;
...but unfortunately, it did not yield the desired outcome.
What steps should I take to properly utilize required and partial to achieve the WithProperties
type as specified?