Skip to content
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

[BUG]: Drizzle typebox not supporting array #1810

Closed
renesass opened this issue Jan 18, 2024 · 4 comments
Closed

[BUG]: Drizzle typebox not supporting array #1810

renesass opened this issue Jan 18, 2024 · 4 comments
Labels

Comments

@renesass
Copy link

renesass commented Jan 18, 2024

What version of drizzle-orm are you using?

0.29.2

What version of drizzle-kit are you using?

0.20.13

Describe the Bug

Hey! I'm using drizzle together with typebox and I get the wrong types when using array. See the following example:

import { pgTable } from 'drizzle-orm/pg-core'
import { createSelectSchema } from 'drizzle-typebox'

const shop = pgTable('shop', {
  images: text('images').array()
})

const shopSchema = createSelectSchema(shop)

// Creates the following object:
// TObject<{ images: TNullable<TString>; }>

Probably related to #1416?

Expected behavior

// TObject<{ images: TNullable<TArray<TString>>; }>

Environment & setup

No response

@renesass renesass added the bug Something isn't working label Jan 18, 2024
@AndriiSherman
Copy link
Member

Marked this PR to be merged

@elliotnash
Copy link

Any updates on this? This still seems to be a problem as of drizzle-orm 0.32.2.

@Huliiiiii
Copy link

Huliiiiii commented Oct 8, 2024

The enumValue of varchar, text is always [string, ...string[]], which cause GetTypeboxType always return TString for any varchar, text, varchar[], text[] column.

type GetTypeboxType<TColumn extends Column> = TColumn['_']['dataType'] extends infer TDataType
? TDataType extends 'custom' ? TAny
: TDataType extends 'json' ? Json
: TColumn extends { enumValues: [string, ...string[]] }
? Equal<TColumn['enumValues'], [string, ...string[]]> extends true ? TString
: TUnion<TUnionLiterals<TColumn['enumValues']>>
: TDataType extends 'array' ? TArray<
GetTypeboxType<
Assume<
TColumn['_'],
{ baseColumn: Column }
>['baseColumn']
>
>
: TDataType extends 'bigint' ? TBigInt
: TDataType extends 'number' ? TNumber
: TDataType extends 'string' ? TString
: TDataType extends 'boolean' ? TBoolean
: TDataType extends 'date' ? TDate
: TAny
: never;

type PgTextBuilderInitial<TName extends string, TEnum extends [string, ...string[]]> = PgTextBuilder<{
name: TName;
dataType: 'string';
columnType: 'PgText';
data: TEnum[number];
enumValues: TEnum;
driverParam: string;
generated: undefined;
}>;

@AndriiSherman
Copy link
Member

This one was fixed in the latest drizzle-typebox@0.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants