K
Kyselyβ€’12mo ago
decho

Unable to compile project with the TypeScript compiler (tsc) v.5.1.6

Hey folks, apologies in advance in case I am missing something obvious. I've noticed something very strange. the tsc compiler which I rarely use (but still need sometimes nevertheless) is unable to compile because of some OnConflictBuilder error, which is way too cryptic for me to understand. I made a bare-minimum reproducible demo here: https://github.com/virtuallyunknown/kysely-tsc-error/ In VSCode while editing and viewing the code, all appears perfectly fine.
GitHub
GitHub - virtuallyunknown/kysely-tsc-error
Contribute to virtuallyunknown/kysely-tsc-error development by creating an account on GitHub.
Solution:
I just released 0.26.0 that has the fix in it
Jump to solution
58 Replies
decho
dechoβ€’12mo ago
ok, it looks like this is a typescript issue. downgrading from typescript 5.1.6 to 5.0.4 makes the error go away and it compiles without any errors. looks like 5.1.3 also works, so something in 5.1.6 caused this issue
Igal
Igalβ€’12mo ago
Hey πŸ‘‹ That's very concerning, this might be also broken going forward in 5.2+
decho
dechoβ€’12mo ago
well you guys should probably report it to the TS team recently 5.1.3 broke another lib (discord.js) but they fixed it with 5.1.6 anyway, just thought i'd let you know, if there is anything i can help with feel free to @me
Igal
Igalβ€’12mo ago
is it still happening with 5.2 beta?
decho
dechoβ€’12mo ago
i haven't tried it, let me see
Igal
Igalβ€’12mo ago
cause their issue template asks to check nightly, probably a good idea to check the upcoming one and its nightly
decho
dechoβ€’12mo ago
typescript@next is that the beta? there is also typescript@beta
Igal
Igalβ€’12mo ago
beta: 5.2.0-beta next: 5.2.0-dev.20230706
beta: 5.2.0-beta next: 5.2.0-dev.20230706
decho
dechoβ€’12mo ago
ok let me test
Igal
Igalβ€’12mo ago
next probably newer cause beta is out for a few days now
decho
dechoβ€’12mo ago
ok so "typescript": "^5.2.0-beta" asked me to change:
"module": "esnext",
"moduleResolution": "NodeNext",
"target": "esnext",

// to

"module": "NodeNext",
"moduleResolution": "NodeNext",
"target": "esnext",

// tsconfig.json:3:19 - error TS5110: Option 'module' must be set to 'NodeNext' when option 'moduleResolution' is set to 'NodeNext'.
"module": "esnext",
"moduleResolution": "NodeNext",
"target": "esnext",

// to

"module": "NodeNext",
"moduleResolution": "NodeNext",
"target": "esnext",

// tsconfig.json:3:19 - error TS5110: Option 'module' must be set to 'NodeNext' when option 'moduleResolution' is set to 'NodeNext'.
after I did it didn't work will test @next now
Igal
Igalβ€’12mo ago
didn't work with same error?
decho
dechoβ€’12mo ago
yep
decho
dechoβ€’12mo ago
Untitled Diff - Diff Checker
kysely-tsc-error@1.0.0 check tsc
src/countries.ts:7:27 - error TS2322: Type 'OnConflictUpdateBu
decho
dechoβ€’12mo ago
exactly the same and unfortunately the same with "typescript": "^5.2.0-dev.20230706" which is npm i typescript@next
Igal
Igalβ€’12mo ago
Do you want to open the issue @ typescript? I'm OK with opening it, but you should get credit for this
decho
dechoβ€’12mo ago
on the typescript github issues you mean?
Igal
Igalβ€’12mo ago
yeah
decho
dechoβ€’12mo ago
i mean, i don't even understand what this error is, you'd be 100x times more qualified for the task and no worries about credit, i mean i just accidentally discovered this, not much to be credited for here but like you and igal are like the main devs, right? if the typescript team ask something you'd know what to tell
Igal
Igalβ€’12mo ago
basically, a generic value was not unwrapped from OnConflictTables<value> to value so it yells about a builder mismatch need to dig into this
decho
dechoβ€’12mo ago
i see
Igal
Igalβ€’12mo ago
its late over here haha, not as sharp atm
decho
dechoβ€’12mo ago
yeah, 3am here same
Igal
Igalβ€’12mo ago
let's open an issue for now @ kysely so people looking for issues see it
decho
dechoβ€’12mo ago
okay, are you asking me to do it or? i can if you want
Igal
Igalβ€’12mo ago
please πŸ™‚
decho
dechoβ€’12mo ago
all right
Igal
Igalβ€’12mo ago
I'm finalizing some changes in JSON PR for another review pass
decho
dechoβ€’12mo ago
GitHub
Unable to compile project with the TypeScript compiler (tsc) v.5.1....
Originally I posted this on the Discord server. Since then we I also found out the issue is specific to TypeScript version 5.1.6. Basically the when you try to build with tsc, it will throw an erro...
Igal
Igalβ€’12mo ago
Thanks! 🫢🏻 I'll try to investigate this tomorrow for the typescript issue, if @koskimas doesn't get to it first. It's a part of the codebase I haven't touched yet, but should still be quite familiar
decho
dechoβ€’12mo ago
no problem at all
Igal
Igalβ€’12mo ago
I can't seem to reproduce this in typescript playground it's only happening when compiling? submitting a PR have a feeling TypeScript had a bug, and we had a bug, and TypeScript never yelled at us for it. but in 5.1.6 they fixed it and started yelling.
decho
dechoβ€’12mo ago
i see you guys have figured it out and fixed it? πŸ‘
koskimas
koskimasβ€’12mo ago
Yep, Igal fixed it.
decho
dechoβ€’12mo ago
amazing job guys do you plan to release a version with this fix applied soon? not that it's urgent for me, just curious
Solution
koskimas
koskimasβ€’12mo ago
I just released 0.26.0 that has the fix in it
decho
dechoβ€’12mo ago
i am reading the patch notes as we speak haha epic thanks for the hard work you guys put into this πŸ‘ Hey @koskimas sorry if this is a stupid question, but do you guys plan allowing WhereExpressionFactory to be used with whereRef or filterWhereRef in future releases, or that's something not possible/bad idea? Right now you can build more complex queries with where and filterWhere, but the ones I mentioned above are just lhs, op, rhs.
koskimas
koskimasβ€’12mo ago
There's no reason to have a callback version of whereRef or filterWhereRef. What are you trying to do?
decho
dechoβ€’12mo ago
well i posted a prediction league demo in #queries a week ago, and in there i thought it would've been helpful for type safety let me try to come up with a super simple example
koskimas
koskimasβ€’12mo ago
All whereRef does is handle the third argument as a reference. If you'd pass in a callback, there's no third argument anymore and the function is 100% equal to where(callback)
decho
dechoβ€’12mo ago
.select(({ fn }) => [
fn.countAll<number>()
.filterWhereRef('predictions.homeTeamScore', '=', 'matches.homeTeamScore')
.filterWhereRef('predictions.awayTeamScore', '=', 'matches.awayTeamScore')
.as('result'),
])
.select(({ fn }) => [
fn.countAll<number>()
.filterWhereRef('predictions.homeTeamScore', '=', 'matches.homeTeamScore')
.filterWhereRef('predictions.awayTeamScore', '=', 'matches.awayTeamScore')
.as('result'),
])
here for example I can chain two filterWhereRef which becomes AND for example what if I wanted this to be an OR
koskimas
koskimasβ€’12mo ago
filterWhere((eb) => eb.or([
eb('predictions.homeTeamScore', '=', eb.ref('matches.homeTeamScore')),
eb('predictions.awayTeamScore', '=', eb.ref('matches.awayTeamScore'))
])
filterWhere((eb) => eb.or([
eb('predictions.homeTeamScore', '=', eb.ref('matches.homeTeamScore')),
eb('predictions.awayTeamScore', '=', eb.ref('matches.awayTeamScore'))
])
decho
dechoβ€’12mo ago
yes, that's the obvious answer, but you lose 100% type safety this way that's how i do it currently
koskimas
koskimasβ€’12mo ago
You lose 0% of type safety that way... What do you mean?
decho
dechoβ€’12mo ago
i could be wrong then
koskimas
koskimasβ€’12mo ago
Yes. All those methods are fully type-safe Are you maybe confusing eb.ref to sql.ref?
decho
dechoβ€’12mo ago
no no, i probably just lack deep understanding i thought there is a chance my question doesn't make sense πŸ˜…
decho
dechoβ€’12mo ago
yeah i know you can do that, but i read somewhere in your docs that whereRef was safer when you're using joins or something like that, could be misremembering otherwise i do it like your demo in my project too
koskimas
koskimasβ€’12mo ago
You can try to change the columns, tables etc in the expression and you'll see errors
decho
dechoβ€’12mo ago
The normal where method treats the right hand side argument as a value by default. whereRef treats it as a column reference. This method is expecially useful with joins and correlated subqueries.
decho
dechoβ€’12mo ago
I guess this is what confused me I have mistakenly thought that if you use where + ref(...) it might be less safer than whereRef but yeah, i've no reason to doubt what you're saying here i think this makes more sense now, whereRef is like a shorthand for conveinence, where is for values and complex logic πŸ‘
Igal
Igalβ€’12mo ago
this is potentially a rotten piece of documentation that needs updating, if you happen to remember where you saw it, would be awesome!
Igal
Igalβ€’12mo ago
whoops πŸ™ˆ
decho
dechoβ€’12mo ago
no no all good, i just misunderstood the docs
Want results from more Discord servers?
Add your server
More Posts