Type inference of queries with expressions in Webstorm
Webstorm reports that the type of
const result = await selectable.select(({ eb }) => eb(eb.fn.count('id'), '>', 0).as('email_exists')).executeTakeFirst()
is {email_exists: SqlBool} | undefined
When I use result?.email_exists
it complains that email_exists
is undefined. And when I tell it to calculate the result's type explicitly it uses any
. Yet when I manually enter the correct signature the error goes away. Is there problem with Webstorm's type inference with kysely or am I doing it wrong?
I notice that there is no problem with simple queries such as select('id')
, without an expression.
https://github.com/esafak/kysely_query_resultsGitHub
GitHub - esafak/kysely_query_results
Contribute to esafak/kysely_query_results development by creating an account on GitHub.
8 Replies
I'm using IntelliJ and it complains like this:
It's very weird. If I replace
executeTakeFirst
to executeTakeFirstOrThrow
, error goes away.Indeed. I've reported it to Jetbrains, and they have duplicated the error: https://youtrack.jetbrains.com/issue/WEB-63454
@Igal I reported this to kysely too but you locked the thread with the label "works as intended". I believe it was too soon to say that. In any case, other users now will not know what to do. https://github.com/kysely-org/kysely/issues/738
GitHub
Queries with functions confuse Webstorm · Issue #738 · kysely-org/k...
When I use selects with expressions Webstorm complains about unresolved variables in the response: const result = await db .selectFrom('person') .select(({ eb }) => eb(eb.fn.count('i...
I haven't locked that thread - check the history again. 🤷🏻♂️
I did label it tho - it's a bug in a specific ide. an ide historically known for typescript weirdness and lagging in features. kysely works as intended as the bug is not in our codebase.
@Emre I locked that thread after providing proof that the issue is not in kysely and you ignoring it.
What do you want us to do to an issue in an IDE? Do you expect us to fix that IDE for you?
How is that proof? The playground does not provide type information.
Yes it does
It uses the same editor as VSCode. It has all the same type information