Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved TypeScript definitions #543

Open
1 task done
Skwai opened this issue Aug 28, 2023 · 3 comments
Open
1 task done

Improved TypeScript definitions #543

Skwai opened this issue Aug 28, 2023 · 3 comments
Labels
dx [Issue] Improvement or fix with impact on the developer experience. improvement [Issue][PR] Refactor or code improvement pending-author [Issue] Awaiting further information or action from the issue author typescript

Comments

@Skwai
Copy link

Skwai commented Aug 28, 2023

Description

As a developer I'd like to have better TypeScript definitions for the SDK. Currently a lot of things are just typed to any.

Eg.

export declare const useAsyncStoryblok: (url: string, apiOptions?: ISbStoriesParams, bridgeOptions?: StoryblokBridgeConfigV2) => Promise<any>;

That just returns a Promise<any> rather than an indication of the type of data it returns. At the very least making it a generic would allow us to manually define the Story schema we're expecting.

Suggested solution or improvement

Better TypeScript definitions. I can see from this project that there are underlying definitions used in the project but they're not exposed:

https://github.com/storyblok/storyblok-js-client/blob/main/src/interfaces.ts

Additional context

No response

Validations

@Skwai Skwai added enhancement [Issue][PR] New feature pending-author [Issue] Awaiting further information or action from the issue author pending-triage [Issue] Ticket is pending to be prioritised labels Aug 28, 2023
@fgalarraga
Copy link

fgalarraga commented Oct 5, 2023

Has there been any updates on this? Trying to get Storyblok, nextjs 13 with app router to work. Seeing this error during build:

Code page.tsx:

import {
  getStoryblokApi, ISbStoriesParams
} from "@storyblok/react/rsc";
import StoryblokStory from "@storyblok/react/story";


export default async function Home() {
  const { data } = await fetchData();

  return (
    <div>
      <StoryblokStory story={data.story} />
    </div>
  )
}

export async function fetchData() {
  let sbParams: ISbStoriesParams = { version: "draft" };

  const storyblokApi = getStoryblokApi();
  return storyblokApi.get(`cdn/stories/home`, sbParams);
}

Here is the build error:

npm run build

> [email protected] build
> next build

 ✓ Creating an optimized production build
 ✓ Compiled successfully
   Linting and checking validity of types  .Failed to compile.

.next/types/app/page.ts:8:13
Type error: Type 'OmitWithTag<typeof import("D:/Repos/testsite/src/app/page"), "metadata" | "default" | "config" | "generateStaticParams" | "revalidate" | "dynamic" | "dynamicParams" | "fetchCache" | "preferredRegion" | "runtime" | "maxDuration" | "generateMetadata", "">' does not satisfy the constraint '{ [x: string]: never; }'.
  Property 'fetchData' is incompatible with index signature.
    Type '() => Promise<ISbResult>' is not assignable to type 'never'.

   6 |
   7 | // Check that the entry is a valid entry
>  8 | checkFields<Diff<{
     |             ^
   9 |   default: Function
  10 |   config?: {}
  11 |   generateStaticParams?: Function
   Linting and checking validity of types  ..

@Dawntraoz Dawntraoz added improvement [Issue][PR] Refactor or code improvement dx [Issue] Improvement or fix with impact on the developer experience. typescript and removed enhancement [Issue][PR] New feature pending-triage [Issue] Ticket is pending to be prioritised labels Mar 5, 2024
@gbyesiltas
Copy link

This package was incredibly useful for us for typing. I'm surprised it's not mentioned anywhere in the readme (it would be even more great if the module implemented this based on some options actually).

@gbyesiltas
Copy link

I just opened a PR that should improve typing for the useAsyncStoryblok composable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dx [Issue] Improvement or fix with impact on the developer experience. improvement [Issue][PR] Refactor or code improvement pending-author [Issue] Awaiting further information or action from the issue author typescript
Projects
None yet
Development

No branches or pull requests

4 participants