You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
SafeQL infers any type on fields that returns an array, leading to a Query has incorrect type annotation error when type any is not passed to this field.
The example below will throw the above error on FoodNames because a type other than any is being passed
typeAnimalWithFoodName={firstName: string;foodNames: string[];};exportasyncfunctionqueryJsonAgg(){returnawaitsql<AnimalWithFoodName[]>` SELECT first_name, (SELECT json_agg(name) FROM foods) AS food_names FROM animals `;}
To Reproduce
Steps to reproduce the behavior:
Setup SafeQL
Use this code in .ts file
typeAnimalWithFoodName={firstName: string;foodNames: string[];};exportasyncfunctionqueryJsonAgg(){returnawaitsql<AnimalWithFoodName[]>` SELECT first_name, (SELECT json_agg(name) FROM foods) AS food_names FROM animals `;}
Expected behavior
A clear and concise description of what you expected to happen.
I expect that SafeQL doesn't throw an error when the correct type is being passed and should infer the correct type
Using type any is not encouraged in TypeScript and should also be discouraged in SafeQL
Screenshots
If applicable, add screenshots to help explain your problem.
Incorrect type annotation error when the correct type is passed
No error when any type is passed
Desktop (please complete the following information):
OS: MAC OS
PostgreSQL version 15
Version [e.g. 22]
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered:
json_agg method returns a json, which by default I map to any since the majority of the Typescript community prefer any over unknown. But you could change that behavior in the overrides.types.
What you want is array_agg instead:
typeAnimalWithFoodName={firstName: string;foodNames: string[];};exportasyncfunctionqueryJsonAgg(){returnawaitsql<AnimalWithFoodName[]>` SELECT first_name, (SELECT array_agg(name) FROM foods) AS food_names FROM animals `;}
Describe the bug
SafeQL infers
any
type on fields that returns an array, leading to aQuery has incorrect type annotation
error when typeany
is not passed to this field.The example below will throw the above error on
FoodNames
because a type other thanany
is being passedTo Reproduce
Steps to reproduce the behavior:
.ts
fileExpected behavior
A clear and concise description of what you expected to happen.
I expect that SafeQL doesn't throw an error when the correct type is being passed and should infer the correct type
Using type
any
is not encouraged in TypeScript and should also be discouraged in SafeQLScreenshots
If applicable, add screenshots to help explain your problem.
Incorrect type annotation error when the correct type is passed
No error when
any
type is passedDesktop (please complete the following information):
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: