client-ts
client-ts copied to clipboard
IntelliJ TS parameter warnings
Describe the bug
IntelliJ (2023.3) Typescript language service raises argument warnings with Xata SDK (0.28) calls such as select
and filter
.
With "email" being a string column:
const page = await xata.db.repro
.filter("email", "email")
.select(["id", "email"])
.getMany();
Filter:
Argument type "email" is not assignable to parameter type FilterColumns<XataRecord> | JSONFilterColumns<XataRecord>
Select:
Argument type string[] is not assignable to parameter type SelectableColumnWithObjectNotation<XataRecord>[]
Assigning Alexis because he had some ideas about a fix for this
Note: this issue surfaced since IntelliJ version 2023.3, it doesn't occur with 2023.2.
I'm having same issue with select
function. When I write it this way
const userRoles = await xataClient.db.usersRoles
.filter({ userId })
.select([{ name: "roles" }])
.getFirst()
WebStorm stops complaining about it, but then I'm losing typing for userRoles
so I can't do
console.log(userRole?.roles)
I mean it works but I'm getting TS2339: Property roles does not exist on type XataRecord<UsersRolesRecord>
. To get rid of this error I need to switch back to .select(["roles"])
. The other option is to call read
function on userRoles
:
console.log((await userRole?.read())?.roles)
but this looks like an overkill.
So, to me it's better to just write
const userRole = await xataClient.db.usersRoles
.filter({ userId })
.select(["roles"])
.getFirst()
console.log(userRole?.roles)
and ignore the IntelliJ issue.