prismicio / prismic-helpers

Set of helpers to manage Prismic data
https://prismic.io/docs/technical-reference/prismicio-helpers
Apache License 2.0
15 stars 9 forks source link

fix: simplify `isFilled.embed()` for better TypeScript compatibility #57

Closed angeloashmore closed 2 years ago

angeloashmore commented 2 years ago

Types of changes

Description

This PR simplifies isFilled.embed() to fix an issue where certain versions of TypeScript cannot parse isFilled.embed()'s bundled type. See #54 for the TypeScript error.

The simplification removes the need for a ternary and infer keyword. See the diff to learn what changes were made.

This changes the bundled type like so. Note the lack of ? in the After type.

Before:

declare const embed: <Field extends {
    [x: string]: never;
} | (AnyOEmbed & {
    embed_url: string;
    html: string | null;
})>(field: (Field extends {
    [x: string]: never;
} | (infer Data extends AnyOEmbed & {
    embed_url: string;
    html: string | null;
}) ? {
    [x: string]: never;
} | (Data & {
    embed_url: string;
    html: string | null;
}) : never) | null | undefined) => field is Field extends {
    [x: string]: never;
} | (infer Data_1 extends AnyOEmbed & {
    embed_url: string;
    html: string | null;
}) ? Data_1 & {
    embed_url: string;
    html: string | null;
} : never;

After:

declare const embed: <
  Field extends
    | {
        [x: string]: never;
      }
    | (AnyOEmbed & {
        embed_url: string;
        html: string | null;
      })
>(
  field: Field | null | undefined
) => field is Extract<
  Field,
  AnyOEmbed & {
    embed_url: string;
    html: string | null;
  }
>;

Fixes #54.

Checklist:

🦊

github-actions[bot] commented 2 years ago

size-limit report 📦

Path Size
dist/index.js 3.13 KB (0%)
dist/index.cjs 3.79 KB (0%)
codecov-commenter commented 2 years ago

Codecov Report

Merging #57 (98150ea) into master (935693b) will decrease coverage by 0.00%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master      #57      +/-   ##
==========================================
- Coverage   99.64%   99.64%   -0.01%     
==========================================
  Files          13       13              
  Lines        1122     1117       -5     
  Branches      112      112              
==========================================
- Hits         1118     1113       -5     
  Misses          4        4              
Impacted Files Coverage Δ
src/isFilled.ts 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

angeloashmore commented 2 years ago

⚠️ Reminder

Inform @faresd when this PR is merged and published.

See this private Slack conversation for details.

angeloashmore commented 2 years ago

Let's ship this one quickly since a user is blocked. Good idea to add type tests after we publish. 👍