how to convert all optional object fields into non-optional

124 views Asked by At

I have the following Object type in Flow:

type Identity = {
  name: string,
  lastName: string
};

type ExtraInfo = {
   favoriteColor: string,
   age: number
};

type Person = {
   a: Identity,
   b?: ExtraInfo
};

Is there a way to define from Person a type without any maybe type?:

// final result, but I don't want to redeclare all the properties, I want to derive from the Person type
type PersonWithExtraInfo = {
   a: Identity,
   b: ExtraInfo
};

I thought that by applying this would work, but apparently, not. Maybe becuase it's not a maybe type what's defined, but an optional property:

type NonMaybeType = <Type>(Type) => $NonMaybeType<Type>;
export type PersonWithExtraInfo = $ObjMap<Person, NonMaybeType>;
0

There are 0 answers