From 88760989def15079c5ab2aefac7ce8e7fb3ad0ad Mon Sep 17 00:00:00 2001 From: Jerred Shepherd Date: Sun, 4 Aug 2024 10:18:06 -0700 Subject: [PATCH] fix: use correct type for verbose --- src/integration.ts | 5 +++-- src/types.ts | 25 ++++++++++++++++--------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/integration.ts b/src/integration.ts index 6a42c99..aa84bad 100644 --- a/src/integration.ts +++ b/src/integration.ts @@ -1,10 +1,11 @@ import type { AstroIntegration } from "astro"; -import type { IntegrationInput, IntegrationOptions } from "./types.js"; +import type { IntegrationDefaults, IntegrationInput, IntegrationOptions } from "./types.js"; import { buildDoneHook } from "./hook.js"; -const defaults = { +const defaults: IntegrationDefaults = { width: 1200, height: 630, + verbose: false, }; export function astroOpenGraphImages({ options, render }: IntegrationInput): AstroIntegration { diff --git a/src/types.ts b/src/types.ts index dfc5d82..96c03d4 100644 --- a/src/types.ts +++ b/src/types.ts @@ -2,21 +2,28 @@ import type { AstroIntegrationLogger, RouteData } from "astro"; import type { ReactNode } from "react"; export interface IntegrationInput { - options: DefaultIntegrationOptions; + options: PartialIntegrationOptions; render: RenderFunction; } -export type DefaultIntegrationOptions = Omit, "height"> & { - width?: number; - height?: number; - verbose: boolean; -}; - -export type IntegrationOptions = DefaultIntegrationOptions & { +/** When applied to PartialIntegrationOptions this type equals IntegrationOptions */ +export interface IntegrationDefaults { width: number; height: number; verbose: boolean; -}; +} + +/** + * IntegrationOptions with some optional properties. This is what we expose to the user. It allows us to + * merge the defaults with the user's options and ensure that all required properties are present. + */ +export type PartialIntegrationOptions = Omit, "height"> & Partial; + +/** + * The options that we use internally. This ensures that all options are configured, either with something + * the user provided or with a default value. + */ +export type IntegrationOptions = PartialIntegrationOptions & IntegrationDefaults; /** This is the page data passed in by Astro */ export interface Page {