Within my application, I have a main object defined with the following structure:
type MainObject = {
name: string;
age: number;
city: string;
}
Now, there is another section in the application that specifically makes use of the properties name
, age
, and city
. The types for this section are as follows:
type NameAge = {
name: string;
age: number;
}
type CityInfo = {
city: string;
}
I am looking for a way to ensure type safety by linking the parent object to these specific child types (NameAge
and CityInfo
) instead of manually creating the entire parent object structure. While using intersections can work, what if the parent object contains additional properties not present in NameAge
or CityInfo
?
Would it be advisable to define an AdditionalType
even if it is not directly utilized in any component?
type AdditionalType = { extra: boolean }
type ParentObject = NameAge & CityInfo & AdditionalType