K
Kyselyβ€’2y 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
dechoOPβ€’2y 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β€’2y ago
Hey πŸ‘‹ That's very concerning, this might be also broken going forward in 5.2+
decho
dechoOPβ€’2y 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β€’2y ago
is it still happening with 5.2 beta?
decho
dechoOPβ€’2y ago
i haven't tried it, let me see
Igal
Igalβ€’2y ago
cause their issue template asks to check nightly, probably a good idea to check the upcoming one and its nightly
decho
dechoOPβ€’2y ago
typescript@next is that the beta? there is also typescript@beta
Igal
Igalβ€’2y ago
beta: 5.2.0-beta next: 5.2.0-dev.20230706
beta: 5.2.0-beta next: 5.2.0-dev.20230706
decho
dechoOPβ€’2y ago
ok let me test
Igal
Igalβ€’2y ago
next probably newer cause beta is out for a few days now
decho
dechoOPβ€’2y 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β€’2y ago
didn't work with same error?
decho
dechoOPβ€’2y ago
yep
decho
dechoOPβ€’2y ago
Untitled Diff - Diff Checker
[email protected] check tsc
src/countries.ts:7:27 - error TS2322: Type 'OnConflictUpdateBu
decho
dechoOPβ€’2y ago
exactly the same and unfortunately the same with "typescript": "^5.2.0-dev.20230706" which is npm i typescript@next
Igal
Igalβ€’2y ago
Do you want to open the issue @ typescript? I'm OK with opening it, but you should get credit for this
decho
dechoOPβ€’2y ago
on the typescript github issues you mean?
Igal
Igalβ€’2y ago
yeah
decho
dechoOPβ€’2y 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β€’2y 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
dechoOPβ€’2y ago
i see
Igal
Igalβ€’2y ago
its late over here haha, not as sharp atm
decho
dechoOPβ€’2y ago
yeah, 3am here same
Igal
Igalβ€’2y ago
let's open an issue for now @ kysely so people looking for issues see it
decho
dechoOPβ€’2y ago
okay, are you asking me to do it or? i can if you want
Igal
Igalβ€’2y ago
please πŸ™‚
decho
dechoOPβ€’2y ago
all right
Igal
Igalβ€’2y ago
I'm finalizing some changes in JSON PR for another review pass
decho
dechoOPβ€’2y 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β€’2y 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
dechoOPβ€’2y ago
no problem at all
Igal
Igalβ€’2y 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
dechoOPβ€’2y ago
i see you guys have figured it out and fixed it? πŸ‘
koskimas
koskimasβ€’2y ago
Yep, Igal fixed it.
decho
dechoOPβ€’2y 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β€’2y ago
I just released 0.26.0 that has the fix in it
decho
dechoOPβ€’2y 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β€’2y ago
There's no reason to have a callback version of whereRef or filterWhereRef. What are you trying to do?
decho
dechoOPβ€’2y 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β€’2y 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
dechoOPβ€’2y 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β€’2y 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
dechoOPβ€’2y ago
yes, that's the obvious answer, but you lose 100% type safety this way that's how i do it currently
koskimas
koskimasβ€’2y ago
You lose 0% of type safety that way... What do you mean?
decho
dechoOPβ€’2y ago
i could be wrong then
koskimas
koskimasβ€’2y ago
Yes. All those methods are fully type-safe Are you maybe confusing eb.ref to sql.ref?
decho
dechoOPβ€’2y ago
no no, i probably just lack deep understanding i thought there is a chance my question doesn't make sense πŸ˜…
decho
dechoOPβ€’2y 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β€’2y ago
You can try to change the columns, tables etc in the expression and you'll see errors
decho
dechoOPβ€’2y 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
dechoOPβ€’2y 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β€’2y 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β€’2y ago
whoops πŸ™ˆ
decho
dechoOPβ€’2y ago
no no all good, i just misunderstood the docs
Want results from more Discord servers?
Add your server