-
-
Notifications
You must be signed in to change notification settings - Fork 22
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
Regression: Some JsonbAgg
types returning unknown
#353
Comments
The types passed in The above-mentioned issue should, of course, be addressed, but the proposed solution will be slightly different from what you might expect. Instead of: type JsonbAgg = { is_guest: boolean; };
type User = { lecturer: JsonbAgg | null };
await sql<User[]>`
SELECT ...
`; You'll need to use a different name than type Lecturer = { is_guest: boolean; };
type User = { lecturer: Lecturer | null };
await sql<User[]>`
SELECT ...
`; |
Great, inference is even better! Confirmed that #354 ( |
@Newbie012 reopening this one, it appears that it is inferring
type User = {
lecturer: {
is_guest: boolean;
} | null;
};
// ✅
await sql<User[]>`
SELECT
CASE
WHEN lecturers.id IS NOT NULL THEN (
jsonb_build_object(
'is_guest',
lecturer_users.email NOT LIKE '%@upleveled.io'
)
)
ELSE NULL
END AS lecturer
FROM
lecturers
INNER JOIN users lecturer_users ON lecturers.user_id = lecturer_users.id
`;
type User = {
lecturer: {
is_guest: boolean;
} | null;
};
// 💥 Query has incorrect type annotation.
// Expected: { lecturer: null | { is_guest: boolean } }[]
// Actual: { lecturer: unknown | null }[]
await sql<User[]>`
SELECT
CASE
WHEN lecturers.id IS NOT NULL THEN (
jsonb_build_object(
'is_guest',
lecturer_users.email NOT LIKE '%@upleveled.io'
)
)
ELSE NULL
END AS lecturer
FROM
lecturers
INNER JOIN users lecturer_users ON lecturers.user_id = lecturer_users.id
`; |
JsonbAgg
types returning unknown
JsonbAgg
types returning unknown
Can you check if 3.6.3 resolves it? I wasn't quite able to reproduce it |
I see it still reproducing with type User = {
lecturer: {
is_guest: boolean;
} | null;
};
// 💥 Query has incorrect type annotation.
// Expected: { lecturer: null | { is_guest: boolean } }[]
// Actual: { lecturer: unknown | null }[]
await sql<User[]>`
SELECT
CASE
WHEN lecturers.id IS NOT NULL THEN (
jsonb_build_object(
'is_guest',
lecturer_users.email NOT LIKE '%@upleveled.io'
)
)
ELSE NULL
END AS lecturer
FROM
lecturers
INNER JOIN users lecturer_users ON lecturers.user_id = lecturer_users.id
`; Here's the table definitions: CREATE TABLE users (
id integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY
);
CREATE TABLE lecturers (
id integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
email varchar(80) UNIQUE,
user_id integer UNIQUE NOT NULL REFERENCES users (id)
); |
Describe the bug
With the
overrides.types.jsonb
configuration:One of my queries which was previously yielding the type
JsonbAgg
now yieldsunknown | null
:Unfortunately,
unknown | null
cannot be used in a type alias (possibly because TypeScript evaluates that to beunknown
):Workaround:
Use the
unknown | null
in an inline generic type argument:So 2 problems here:
JsonbAgg
type is no longer returned hereunknown | null
probably should never be inferred by SafeQL, because it's not compatible with TypeScriptunknown | null
inside of a type aliasTo Reproduce
Steps to reproduce the behavior: See above
Expected behavior
lecturer
receives aJsonbAgg
type (or a specific type based onjsonb_build_object
inference), as SafeQL did before the versions released for literal inference:Screenshots
--
Desktop (please complete the following information):
Additional context
Problem seems to have been introduced in the versions released for literal inference:
The text was updated successfully, but these errors were encountered: