#getCollection() filter type error

8 messages · Page 1 of 1 (latest)

rigid breach
#

I am trying to filter collection queries by sub-directory as described here in the docs: https://docs.astro.build/en/guides/content-collections/#querying-collections

Following the example for filtering entries, my code looks like this:


const posts = await getCollection("docs", ({id}) => {
    return id.startsWith("v1/");
});```

i.e. I only want to get entries under the v1 subdirectory under content/docs/v1

Intellisense confirms that `id` points to all the entries I have in my v1 and v2 subdirectories. However, I get this type error in the filter function parameter

> Argument of type '({ id }: CollectionEntry<"zine">) => boolean' is not assignable to parameter of type '(entry: CollectionEntry<"zine">) => entry is CollectionEntry<"zine">'.
>   Signature '({ id }: CollectionEntry<"zine">): boolean' must be a type predicate. ts(2345)

To be clear, this code still works and filters the entries as intended. However, I am not sure how to get the TS compiler to stop complaining.
Astro Documentation

Content collections help organize your Markdown and type-check your frontmatter with schemas.

abstract juniper
#

This is a bug that just got patched in v2.02, if you update to latest version it should be fixed

rigid breach
#

Confirming I am on v2.02. My site builds just fine, but I still get the annoying TS warning

abstract juniper
#

Do you still have error if you run npx astro sync

rigid breach
#

Ran npx astro sync but the warnings persist

#

The errors disappeared at first but when I click back into the respective files they reappear

abstract juniper
#

I guess it didn't get fixed