Transforming Optional Values to an Object with Optional Properties in TypeScript

what's the best way to transform something like:

const email = "hello@word.com"
const displayName = Option.none()

// To type =>

type Attendee = {
  email: string,
  displayName?: string
}


?

My attemps so far but, it feels wrong
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,
      },
    ),
  };
Was this page helpful?