Transforming Optional Values to an Object with Optional Properties in TypeScript
what's the best way to transform something like:
?
My attemps so far but, it feels wrong
?
My attemps so far but, it feels wrong
const email = "hello@word.com"
const displayName = Option.none()
// To type =>
type Attendee = {
email: string,
displayName?: string
}Record.getSomes({ email: Option.Some(email), displayName: getDisplayName() }
// But result inferred as Record<string, string>
// This code works but I wonder if there is simplier way
{
email: email,
...Option.match(
getDisplayName(),
{
onSome: (displayName) => ({ displayName }),
onNone: () => Record.empty,
},
),
};