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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys.contentType.sys.id string is not assignable to string literal #56

Open
builtbyjay opened this issue Feb 4, 2021 · 0 comments
Open

Comments

@builtbyjay
Copy link

Hello 馃槃 first of all, amazing package, thank you for releasing and maintaining it.

I've noticed that when I try and define the return type of the getStaticProps() function (Next.js), if I use an interface that defines the contentType I get a typescript error on the contentType.sys.id property, complaining that type string is incompatible with the string literal (in my example, "city").

Here's the code snippet:

interface Props {
  cities: ICity[];
}

export const getStaticProps: GetStaticProps<Props> = async context => {
  const client = createClient({
    space: process.env.CONTENTFUL_SPACE,
    accessToken: process.env.CONTENTFUL_TOKEN
  });

  const cities = await client.getEntries<ICityFields>({
    content_type: 'city'
  });

  return {
    props: {
      cities: cities.items
    }
  }
}

And a snapshot of the error:

Screen Shot 2021-02-04 at 11 38 01

For now, I'm asserting the type in the return statement to make the error go away - which isn't much of an inconvenience tbh. Is this the correct solution?

  return {
    props: {
      cities: cities.items as ICity[]
    }
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant