valtyr/prisma-kysely

Database results is not a compatible type of generated types

Closed this issue ยท 3 comments

Hi. It seems that the results from fetching the database are not compatible to what prisma-kysely generates as types, with this issue occuring only on the Generated field.

The error given: Type 'number' is not assignable to type 'ColumnType<number, number | undefined, number>'

The error occurs when attempting to pass a value to a function which expects a type generated by prisma-kysely, however, it works fine when using the Prisma generated type or the query return type.

const applications = await ctx.db
	.selectFrom("DelegationApplication")
	.selectAll()
	.execute()

const fnA = (a: DelegationApplication): number => a.actualSize // this line errors, imported prisma-kysely type
const fnB = (b: (typeof applications)[0]): number => b.actualSize
const fnC = (c: PrismaDelegationApplication): number => c.actualSize // imported Prisma type

Hey ๐Ÿ‘‹

This is not prisma-kysely related.

You should use:

import { Selectable } from 'kysely'

const fnA = (a: Selectable<DelegationApplication>): number => a.actualSize

Another option:

Import { InferResult } from 'kysely'

const query = await ctx.db
	.selectFrom("DelegationApplication")
	.selectAll()

type Applications = InferResult<typeof query>

const application = await query.execute()

const fnB = (b: Applications[number]): number => b.actualSize

Ah okay, that makes sense. Thanks for the help. Would it however make sense to add this to the Gotchas section of the README? As far as I know, there is no mention of this in the kysely docs.

valtyr commented

I'll take that into consideration the next time I revise the README. Closing this for now :D