Based on the information provided in the knowledge sources, I can explain why this is happening and suggest a way to prevent it.
The issue you're experiencing is related to how Astro's content collections handle entry IDs. According to the Content Collections API Reference, each entry in a collection must have a unique id property. This is a requirement for all content entries, regardless of how they are loaded.
When you return an array of objects from your custom loader, Astro automatically includes the id property in the entry data. This is why you're seeing the id property in your collection entries, even though you didn't explicitly include it in your Record<string, number[]> type.
To prevent this and ensure that your collection entries only contain the data you expect, you can use the DataEntry type from the Content Loader API. Here's how you can modify your loader to achieve this:
import { defineCollection } from 'astro:content';
import type { DataEntry } from 'astro/content';
const kwords = defineCollection({
loader: async () => {
const kws = import.meta.glob('./content/kw-x-doc/*.json', { import: 'default' });
const result: DataEntry[] = [];
for (const path in kws) {
const id = path.slice(19, -5).toLowerCase();
const data = await kws[path]() as Record<string, number[]>;
result.push({
id,
data,
});
}
return result;
}
});
In this modified version:
- We import the
DataEntry type from astro/content.
- We create objects that conform to the
DataEntry structure, which separates the id from the actual data.
- The
data property contains your Record<string, number[]>, while the id is kept separate.