K
Kysely•2y ago
bombillazo

jsonArrayFrom with `as` not being typed

I have the following query
await db
.selectFrom('user')
.selectAll()
.select((eb) => [
jsonArrayFrom(
eb
.selectFrom('book')
.selectAll()
.where('book.is_enabled', '=', true)
).as('books'),
])
.execute();
await db
.selectFrom('user')
.selectAll()
.select((eb) => [
jsonArrayFrom(
eb
.selectFrom('book')
.selectAll()
.where('book.is_enabled', '=', true)
).as('books'),
])
.execute();
but the resulting query is not seeing the jsonArrayFrom field with the name books , rather it types it like this:
{
[x: string]: {
created_at: TimestampTZ;
description: string | null;
id: string;
label: string | null;
name: string;
is_enabled: boolean;
}[];
... 5 more ...;
name: string;
}[]
{
[x: string]: {
created_at: TimestampTZ;
description: string | null;
id: string;
label: string | null;
name: string;
is_enabled: boolean;
}[];
... 5 more ...;
name: string;
}[]
How can i fix this?
Solution:
so Im using deno, and it uses import maps to import deps, I have these 2 import paths set up: I forgot to bump the helper path version to 0.27.3 as well šŸ¤¦ā€ā™‚ļø...
No description
Jump to solution
14 Replies
Igal
Igal•2y ago
Hey šŸ‘‹ This works fine in the playground. Is tsconfig.json#compilerOptions.strict not true by any chance?
bombillazo
bombillazoOP•2y ago
let me check yes, it is true hey, somethign weird, this happens on kysely v 0.27.3, not on 0.27.2 hmmmm esm.sh CDN has a kysely version for 0.27.3, but the GH releases stop at 0.27.2 it works for 0.27.2
Igal
Igal•2y ago
the playground can use 0.27.3, 0.27.2, etc. this is something local what typescript version?
bombillazo
bombillazoOP•2y ago
what chagnes occurred for .3? I dont see them in the release notes. Im using TS 5.4.4
Igal
Igal•2y ago
We haven't posted a release, nothing major
bombillazo
bombillazoOP•2y ago
its strange that there is no TS problem on 0.27.2 but there is for 0.27.3, using the same TS version
Igal
Igal•2y ago
can you share your Database interface with just the two tables?
bombillazo
bombillazoOP•2y ago
sure, one sec
declare const TimestampTZ: unique symbol;

export type TimestampTZ = string & { _opaque: typeof TimestampTZ };

export type DBTimestampTZ = ColumnType<TimestampTZ, TimestampTZ, TimestampTZ>;

export interface BookTable {
created_at: Generated<DBTimestampTZ>;
description: string | null;
id: Generated<string>;
is_enabled: Generated<boolean>;
label: string;
name: string;
}

export interface UserTable {
created_at: Generated<DBTimestampTZ>;
description: string | null;
id: Generated<string>;
name: string;
interests: string[]
email: string;
level: number;
birthdate: string;
score: number;
}

export interface KyselyDB {
user:UserTable,
book: BookTable,
}
declare const TimestampTZ: unique symbol;

export type TimestampTZ = string & { _opaque: typeof TimestampTZ };

export type DBTimestampTZ = ColumnType<TimestampTZ, TimestampTZ, TimestampTZ>;

export interface BookTable {
created_at: Generated<DBTimestampTZ>;
description: string | null;
id: Generated<string>;
is_enabled: Generated<boolean>;
label: string;
name: string;
}

export interface UserTable {
created_at: Generated<DBTimestampTZ>;
description: string | null;
id: Generated<string>;
name: string;
interests: string[]
email: string;
level: number;
birthdate: string;
score: number;
}

export interface KyselyDB {
user:UserTable,
book: BookTable,
}
Igal
Igal•2y ago
can you share the definition of DBTeimstampTZ ?
bombillazo
bombillazoOP•2y ago
updated*
Igal
Igal•2y ago
where did you import jsonArrayFrom from ?
bombillazo
bombillazoOP•2y ago
aaaaaaaah šŸ™‚
Solution
bombillazo
bombillazo•2y ago
so Im using deno, and it uses import maps to import deps, I have these 2 import paths set up: I forgot to bump the helper path version to 0.27.3 as well šŸ¤¦ā€ā™‚ļø
No description
bombillazo
bombillazoOP•2y ago
now its fixed, thanks šŸ˜„

Did you find this page helpful?