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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SDK] Unable to resolve inferred partial field types, when using _and/_or filters in queries #20633
Comments
What is the actual issue you're seeing? I dont directly see anything wrong with that generated type but is always hard to tell without the appropriate context. |
The TypeScript issue I'm facing involves incorrect type resolution for queries. Ideally, only the queried fields should be resolved, but instead, it resolves the entire object type from the collection, when filtering additionally with _and/_or filters. Edit: The first example is showing a correct example. The second the kinda buggy one. |
Mind sharing the important parts of the schema for reproduction too? the root and product types should do.
If not related to the issue it will be related to the PR as thats where these conditionals were implemented |
I uploaded a test repo here https://github.com/sensedrive/directus-types-test Filtering with or without _and makes a significant difference in the response types. You should see an ts errror in line 16. Or I am doing something wrong ... |
I face a similar problem. Actually what i run into is when i want to filter a readItems the filter couldn't be partial. export const findServiceBySlug = async (slug: string) => {
const service = await directus.request(
readItems("service", {
fields: ["*", { fimg: ["*"] }, { block_image: ["*"] }],
filter: { slug: { _eq: slug } },
limit: 1,
})
); And ts throw this error underlining the world filter:
@sensedrive The only solution I find for now is using //ts-ignore |
Describe the Bug
I am using the SDK (13.0.2) with Types.
With the SDK it is possible to retrieve the types of the partial object, when explitely queriing single fields like in the example below.
I get
const response: Merge<MapFlatFields<object & Product, "id" | "title", MappedFunctionFields<Collections, object & Product>>, {}>[]
To Reproduce
But when I additionally filter with _and/_or I get the type for the whole object back.
const response: Merge<MapFlatFields<object & Product, keyof Product | FunctionFields<Collections, Product>, MappedFunctionFields<Collections, object & Product>>, {}>[]
Maybe this ticket is connected with the following issue? #19285
Thank you in advance
Directus Version
v10.7.2
Hosting Strategy
Self-Hosted (Docker Image)
The text was updated successfully, but these errors were encountered: