Skip to content

Typescript error for Content Collection: post with reference("tags") gives "No overload matches this call" #8450

@teinett

Description

@teinett

Astro Info

Astro                    v3.0.10
Node                     v18.17.0
System                   macOS (x64)
Package Manager          npm
Output                   server
Adapter                  @astrojs/node
Integrations             astro-compress

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

I have a page of one post and want to show all tags from this post: src/pages/posts/[slug].astro


---
export const prerender = true;

import type { CollectionEntry } from "astro:content";
import { getEntry, getEntries } from "astro:content";
import { getCollection } from "astro:content";

interface Props {
    post: CollectionEntry<"posts">;
}

const { post } = Astro.props;

export async function getStaticPaths() {
    const allPosts = await getCollection("posts");
    return allPosts.map((post) => ({
        params: { slug: post.slug },
        props: { post },
    }));
}

const { Content } = await post.render();

// get tags data from current post
const tags = await getEntries(post.data.tags);
...

---
...

I receive an error in VS Code:

No overload matches this call.
  Overload 1 of 2, '(entries: { collection: "tags"; slug: "black" | "red" | "white"; }[]): Promise<(({ id: "black.md"; slug: "black"; body: string; collection: "tags"; data: { cover?: { src: string; width: number; height: number; format: "png" | ... 5 more ... | "svg"; } | undefined; title: string; }; } & { ...; }) | ({ ...; } & { ...; }) | ({ ...; } & { ...; }))[]>', gave the following error.
  Overload 2 of 2, '(entries: { collection: never; id: string | number | symbol; }[]): Promise<never[]>', gave the following error.ts(2769)

Screenshot:

Снимок экрана 2023-09-07 в 08 51 30

What's the expected result?

I follow official docs: https://docs.astro.build/en/guides/content-collections/#accessing-referenced-data
I expect to have no errors.

Link to Minimal Reproducible Example

https://github.com/teinett/learn-astro-images

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

Labels

- P3: minor bugAn edge case that only affects very specific usage (priority)feat: content collectionsRelated to the Content Collections feature (scope)needs responseIssue needs response from OP

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions