Skip to content

🐛 [Bug]: Type error when passing Astro object to getLiveStory #355

@LuisWolf-Snapaddy

Description

@LuisWolf-Snapaddy

Package

@storyblok/astro (Astro Integration)

Bug Description

When trying to use the getLiveStory there is a type mismatch between the required Astro global and the actual one. This always happens when you use e.g. getStaticPaths(), which changes the type of the global.

Steps to Reproduce

  1. Use the astro/tsconfigs/strict config for strict type checks
  2. Create a getStaticPaths() function that returns some GetStaticPathsResult.
  3. Try to use getLiveStory
  4. Run astro check or see the error in your editor

Expected Behavior

Should not produce a type error even in strict mode

Actual Behavior

Does produce an error:

Argument of type 'Readonly<AstroGlobal<never, (_props: never) => any, { slug: string; }>>' is not assignable to parameter of type 'Readonly<AstroGlobal<Record<string, any>, AstroComponentFactory, Record<string, string | undefined>>>'.
  Types of property 'self' are incompatible.

Code Sample

---
import { getLiveStory } from '@storyblok/astro';

export function getStaticPaths() {
  const paths: Array<{ params: { slug: string } }> = [];
  return paths;
}

const liveStory = await getLiveStory(Astro);
---

Environment

npmPackages:
    @storyblok/astro: ^7.3.3 => 7.3.3
    astro: ^5.14.5 => 5.14.5

Additional Context

  1. This only happens when you specify functions that update the Astro global like getStaticPaths
  2. This only happens when you use at least Astros strict TypeScript preset, not in the base one.

The problem was already mentioned in #99 but "could not be reproduced". Probably because it does not happen with the Astros base ts config.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugpending-triage[Status] Ticket is pending to be prioritised

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions