Skip to content

Commit

Permalink
fix: stricter href/field prop types for PrismicLink
Browse files Browse the repository at this point in the history
  • Loading branch information
angeloashmore committed Jul 13, 2021
1 parent 76ad782 commit 5dec44a
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions src/PrismicLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,7 @@ export type PrismicLinkProps<
target?: string;
rel?: string;
children?: React.ReactNode;
} & (
| {
field: prismicT.LinkField;
href?: never;
}
| {
field?: never;
href: string;
}
);
} & ({ field: prismicT.LinkField } | { href: string });

const defaultInternalComponent = "a";
const defaultExternalComponent = "a";
Expand All @@ -53,13 +44,13 @@ export const PrismicLink = <
const linkResolver = props.linkResolver || context.linkResolver;

const href =
props.href ||
(props.field && prismicH.asLink(props.field, linkResolver)) ||
"";
("href" in props
? props.href
: prismicH.asLink(props.field, linkResolver)) || "";

const target =
props.target ||
(props.field && "target" in props.field && props.field.target) ||
("field" in props && "target" in props.field && props.field.target) ||
undefined;

const rel =
Expand Down

0 comments on commit 5dec44a

Please sign in to comment.