Jon Koops
Jon Koops
DTDrizzle Team
Created by Jon Koops on 6/8/2024 in #help
No type inference when specifying a reference.
Hmmm, upon closer inspection I need a seperate table to link both together, so perhaps what I am doing here is invalid.
5 replies
DTDrizzle Team
Created by Jon Koops on 6/8/2024 in #help
No type inference when specifying a reference.
5 replies
DTDrizzle Team
Created by Jon Koops on 6/8/2024 in #help
No type inference when specifying a reference.
I have a feeling this is a circular reference issue, as when I remove the .references(() => invitations.id), from invitationId this all seems to work.
5 replies
DTDrizzle Team
Created by Jon Koops on 6/8/2024 in #help
No type inference when specifying a reference.
This is all fine, until I want to add a reference from primary_guest_id to the guest id. If I change the following line:
primaryGuestId: integer('primary_guest_id').notNull(),
primaryGuestId: integer('primary_guest_id').notNull(),
to:
primaryGuestId: integer('primary_guest_id').notNull().references(() => guests.id),
primaryGuestId: integer('primary_guest_id').notNull().references(() => guests.id),
Now suddenly the ORM is no longer able to infer a TypeScript type (both invitations and guests are any, and I get the following errors:
'invitations' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
'guests' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
'invitations' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
'guests' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
It seems however that Drizzle kit is able to create the SQL:
CREATE TABLE `guests` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`first_name` text NOT NULL,
`last_name` text NOT NULL,
`invitation_id` integer NOT NULL,
FOREIGN KEY (`invitation_id`) REFERENCES `invitations`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE TABLE `invitations` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`status` text NOT NULL,
`email` text NOT NULL,
`notes` text,
`primary_guest_id` integer NOT NULL,
FOREIGN KEY (`primary_guest_id`) REFERENCES `guests`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE UNIQUE INDEX `invitations_email_unique` ON `invitations` (`email`);
CREATE TABLE `guests` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`first_name` text NOT NULL,
`last_name` text NOT NULL,
`invitation_id` integer NOT NULL,
FOREIGN KEY (`invitation_id`) REFERENCES `invitations`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE TABLE `invitations` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`status` text NOT NULL,
`email` text NOT NULL,
`notes` text,
`primary_guest_id` integer NOT NULL,
FOREIGN KEY (`primary_guest_id`) REFERENCES `guests`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE UNIQUE INDEX `invitations_email_unique` ON `invitations` (`email`);
Why are my TypeScript types getting borked? How can this be fixed?
5 replies