Open SSardorf opened 11 months ago
The problem is that T['data']
is used for both the insert and select type. As a workaround you can type it as Vector
only and then if you want to insert a number[]
just type cast it. See the example.
Can you change the title to be "Allow different input/output types on customTypes"?
What version of
drizzle-orm
are you using?0.29.1
What version of
drizzle-kit
are you using?No response
Describe the Bug
In the following code, when you insert, you should be able to input both
Vector
andnumber[]
Both of these work:
This is great, however, given the fromDriver ALWAYS returns a vector, it should be able to correctly infer that it's a
Vector
type. However, when querying the database, it returns asVector | number[]
It seems to simply use the
data: Vector | number[];
type from thecustomType
, however I've looked in the codebase and it should be able to infer the type based on thefromDriver
. https://github.com/drizzle-team/drizzle-orm/blob/0a4e3b265ce121675e7baa14f3a39669ea387e6d/drizzle-orm/src/pg-core/columns/custom.ts#L60-L83Expected behavior
Custom types should be able to have different input/output types. Being able to transform data at the ORM-level would be such a powerful ability, in ensuring that data is always the format that you want it to be, without having to transform on every query.
Environment & setup
No response