nuxt-modules / nuxt-modules/strapi
Defining Type for relations breaks typescript when creating filters
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 717
- Forks
- 89
- Avg merge
- 7h 3m
- Merged PRs (30d)
- 6
Description
I have the following typescript type:
export type StrapiPage = {
parent?: Strapi4ResponseSingle<StrapiPage>;
localizations?: Strapi4ResponseMany<StrapiPage>;
}
Then, when i try to run a find with the following filter to get all pages without a parent.
return {
parent: {
slug: {
$null: true
}
}
};
the following error occurs:
Object literal may only specify known properties, and 'slug' does not exist in type 'StrapiPrimitiveOperators | { data?: { id?: StrapiPrimitiveOperators | StrapiNumberOperators | undefined; attributes?: { ...; } | undefined; meta?: { ...; } | undefined; } | undefined; meta?: { ...; } | undefined; }'.
If i write it like this, the error is gone, but ofcourse the filters don't work anymore:
return {
parent: {
data: {
attributes: {
slug: {
$null: true
}
}
}
}
};
I understand this is because the return value/structure is different from the filter structure, but i'm not sure how to fix this in my StrapiPage type?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start from the StrapiPage type shown in the issue and trace the filter type that is inferred for its parent relation. Compare the relation response shape with the filter shape, then run the project's TypeScript checks. Done means a parent slug $null filter is accepted by the type system and the existing filter structure remains usable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100