Modeling Parent Relationships Results in TS Error

When you have a data structure like this:
export const comment = mysqlTable('crawl_item', {
id: cuid2('id').primaryKey().notNull(),
parent: cuid2('parent').references(() => comment.id),
});
export const comment = mysqlTable('crawl_item', {
id: cuid2('id').primaryKey().notNull(),
parent: cuid2('parent').references(() => comment.id),
});
You see the error:
'comment' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
'comment' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
Is there a workaround? This is blocking us unfortunately.
2 Replies
Marcus
Marcus9mo ago
Looks like this works?
export const comment = mysqlTable('crawl_item', {
id: cuid2('id').primaryKey().notNull(),
parent: cuid2('parent').references((): AnyMySqlColumn => comment.id),
});
export const comment = mysqlTable('crawl_item', {
id: cuid2('id').primaryKey().notNull(),
parent: cuid2('parent').references((): AnyMySqlColumn => comment.id),
});
Angelelz
Angelelz9mo ago
This is the way
Want results from more Discord servers?
Add your server