Closed Eprince-hub closed 2 months ago
@Newbie012 what do you think about this one?
I can confirm that this can be reproduced with a nullable boolean
field (without NOT NULL
).
It appears that SafeQL is reading the TS type boolean | null
to be null | false | true
, which fails equality test with null | boolean
from PostgreSQL inference.
Is it a small change in SafeQL to infer null | false | true
instead of boolean | null
from the TS type?
Use Omit<>
and a TypeScript intersection:
export type Animal = {
isAdmin: boolean | null;
};
export async function getAnimal() {
- return await sql<Animal[]>`
+ return await sql<(Omit<Animal, 'isAdmin'> & { isAdmin: boolean | null })[]>`
SELECT
animals.is_admin
FROM
animals
`;
}
@Newbie012 thanks for the PR #264 and the release!
I can confirm that @ts-safeql/eslint-plugin@3.4.3
is working with nullable boolean
fields 🎉
Describe the bug SafeQL throws an
Incorrect type annotation
error when a boolean field is also allowed to be null. Querying theis_admin
field of the database table below with the typeisAdmin: boolean | null
will throw the errorTo Reproduce Steps to reproduce the behavior:
public
env variables with your database credentialsdatabase.ts
fileExpected behavior There may be some cases where the union type of
boolean | null
is needed, and SafeQL should support that. So there shouldn't be an error when I have a field like thisis_admin boolean
and a type like thisisAdmin: boolean | null
Screenshots
Desktop (please complete the following information):
Additional context Add any other context about the problem here.