'how to convert all optional object fields into non-optional
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>;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
