K
Kyselyā€¢8mo 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ā€¢8mo ago
Hey šŸ‘‹ This works fine in the playground. Is tsconfig.json#compilerOptions.strict not true by any chance?
bombillazo
bombillazoOPā€¢8mo 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ā€¢8mo ago
the playground can use 0.27.3, 0.27.2, etc. this is something local what typescript version?
bombillazo
bombillazoOPā€¢8mo ago
what chagnes occurred for .3? I dont see them in the release notes. Im using TS 5.4.4
Igal
Igalā€¢8mo ago
We haven't posted a release, nothing major
bombillazo
bombillazoOPā€¢8mo 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ā€¢8mo ago
can you share your Database interface with just the two tables?
bombillazo
bombillazoOPā€¢8mo 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ā€¢8mo ago
can you share the definition of DBTeimstampTZ ?
bombillazo
bombillazoOPā€¢8mo ago
updated*
Igal
Igalā€¢8mo ago
where did you import jsonArrayFrom from ?
bombillazo
bombillazoOPā€¢8mo ago
aaaaaaaah šŸ™‚
Solution
bombillazo
bombillazoā€¢8mo 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ā€¢8mo ago
now its fixed, thanks šŸ˜„
Want results from more Discord servers?
Add your server