Improving Data Extraction Logic

Is there a better way to do that?
const extract = (url: string) =>
  Effect.andThen(
    Effect.tryPromise(() => article(url)),
    (data) => {
      if (
        data === null ||
        data.title === undefined ||
        data.published === undefined ||
        data.source === undefined ||
        data.content === undefined
      ) {
        return Effect.fail('Data is incomplete');
      }
      return Effect.succeed({
        title: data.title,
        published: data.published,
        source: data.source,
        content: data.content,
      });
    },
  );
Was this page helpful?