client-ts icon indicating copy to clipboard operation
client-ts copied to clipboard

IntelliJ TS parameter warnings

Open kostasb opened this issue 1 year ago • 3 comments

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>[]

image

kostasb avatar Dec 12 '23 12:12 kostasb

Assigning Alexis because he had some ideas about a fix for this

eemmiillyy avatar Dec 12 '23 12:12 eemmiillyy

Note: this issue surfaced since IntelliJ version 2023.3, it doesn't occur with 2023.2.

kostasb avatar Dec 12 '23 14:12 kostasb

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.

mkurczewski avatar Dec 19 '23 09:12 mkurczewski