-
Notifications
You must be signed in to change notification settings - Fork 281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typechecking doesn't work when insert value is instantiated outside the values function #641
Comments
Hey 👋 This is a general TypeScript problem. I'll try to find the relevant issue/s later. Lemme give you another weird behavior: const values = {
first_name: 'Jennifer',
last_name: 'Aniston',
age: 40,
hello: 'world'
}
const result = await db
.insertInto('person')
.values([values, {
first_name: 'Jennifer',
last_name: 'Aniston',
age: 40,
hello: 'world'
}])
.executeTakeFirst() no type errors. const values = {
first_name: 'Jennifer',
last_name: 'Aniston',
age: 40,
hello: 'world'
}
const result = await db
.insertInto('person')
.values([{
first_name: 'Jennifer',
last_name: 'Aniston',
age: 40,
hello: 'world'
}, values])
.executeTakeFirst() again, no type-errors. if you add I actually had a PR that "fixes" it with a hack, but we rightfully didn't merge it as it's unhealthy. This is TypeScript's responsibility to fix. |
hmm but even with const obj = {
first_name: 'Jennifer',
last_name: 'Aniston',
age: 40,
hello: 'world'
} as const
const result = await db
.insertInto('person')
.values(obj)
.executeTakeFirst()
console.log(result.insertId) |
It worked on the 2 item example, haven't checked on single value example. Here's some related text from people who are more in the know about this issue. |
Okay, so typescript allows additional members, which makes sense. What doesn't make sense is why this is valid... const obj = {
first_name: 'Jennifer',
last_name: 'Aniston',
age: 40,
hello: 'world'
}
const result = await db
.insertInto('person')
.values(obj)
.executeTakeFirst() but this is not... const result = await db
.insertInto('person')
.values({
first_name: 'Jennifer',
last_name: 'Aniston',
age: 40,
hello: 'world'
})
.executeTakeFirst() If the explanation is that the additional members are not type errors, then both of these should be valid. Something else is going on here |
What can you do, when one of TypeScript's team says: "works as intended". 🤷
|
I think Thanks for everything! |
In this playground link: https://kysely.dev/docs/examples/INSERT/single-row
This gets correctly typechecked. Column
hello
doesn't exist and there's squiggly lines everywhere.This, however, doesn't work.
Same thing for updates.
This is quite a footgun!
The text was updated successfully, but these errors were encountered: