TypeScript type errors when running in PNPM workspace
I changed nothing about my code other than doing a full clean build. Working code now failing with type errors.
I am on version:
I am getting this error:
There's nothing strange about my schema that i can tell:
"drizzle-orm": "^0.29.1",
"drizzle-orm": "^0.29.1",
frontend/src/server/list-files.ts(37,11): error TS2322: Type 'PgColumn<{ name: "state"; tableName: "place"; dataType: "string"; columnType: "PgVarchar"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>' is not assignable to type 'SQL<unknown> | Aliased<unknown> | PgColumn<ColumnBaseConfig<ColumnDataType, string>, {}, {}> | PgTable<TableConfig> | SelectedFieldsFlat<...>'.
Type 'PgColumn<{ name: "state"; tableName: "place"; dataType: "string"; columnType: "PgVarchar"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>' is not assignable to type 'SelectedFieldsFlat<PgColumn<ColumnBaseConfig<ColumnDataType, string>, {}, {}>>'.
Index signature for type 'string' is missing in type 'PgColumn<{ name: "state"; tableName: "place"; dataType: "string"; columnType: "PgVarchar"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>'.
frontend/src/server/list-files.ts(37,11): error TS2322: Type 'PgColumn<{ name: "state"; tableName: "place"; dataType: "string"; columnType: "PgVarchar"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>' is not assignable to type 'SQL<unknown> | Aliased<unknown> | PgColumn<ColumnBaseConfig<ColumnDataType, string>, {}, {}> | PgTable<TableConfig> | SelectedFieldsFlat<...>'.
Type 'PgColumn<{ name: "state"; tableName: "place"; dataType: "string"; columnType: "PgVarchar"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>' is not assignable to type 'SelectedFieldsFlat<PgColumn<ColumnBaseConfig<ColumnDataType, string>, {}, {}>>'.
Index signature for type 'string' is missing in type 'PgColumn<{ name: "state"; tableName: "place"; dataType: "string"; columnType: "PgVarchar"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>'.
Index signature for type 'string' is missing in type 'PgColumn<{ name: "state"; tableName: "place"; dataType: "string"; columnType: "PgVarchar"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>
Index signature for type 'string' is missing in type 'PgColumn<{ name: "state"; tableName: "place"; dataType: "string"; columnType: "PgVarchar"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>
const page = await db
.select({
state: place.state, // <- error here
county: place.county, // <- and here, etc.
city: place.city,
transcriptFile: hearing.transcriptFile,
transcriptFileTxt: hearing.transcriptFileTxt,
minutesFile: hearing.minutesFile,
minutesFileTxt: hearing.minutesFileTxt,
date: hearing.date,
})
.from(hearing)
const page = await db
.select({
state: place.state, // <- error here
county: place.county, // <- and here, etc.
city: place.city,
transcriptFile: hearing.transcriptFile,
transcriptFileTxt: hearing.transcriptFileTxt,
minutesFile: hearing.minutesFile,
minutesFileTxt: hearing.minutesFileTxt,
date: hearing.date,
})
.from(hearing)
import {
date,
pgEnum,
pgSchema,
primaryKey,
text,
varchar,
} from "drizzle-orm/pg-core";
export const place = public_db.table("place", {
placeId: varchar("place_id").notNull().primaryKey(),
state: varchar("state", { length: 2 }).notNull(),
county: text("county").notNull(),
city: text("city"),
createdAt: date("created_at").defaultNow(),
});
export const hearing = public_db.table(
"hearing",
{
placeId: varchar("place_id")
.notNull()
.references(() => place.placeId),
date: date("date").notNull(),
boardType: BoardType("board_type").notNull(),
commissioners: text("commissioners"),
createdAt: date("created_at").defaultNow(),
minutesFile: text("minutes_file"),
minutesFileTxt: text("minutes_file_txt"),
videoFile: text("video_file"),
transcriptFile: text("transcript_file"),
transcriptFileTxt: text("transcript_file_txt"),
},
(table) => ({
pk: primaryKey({
columns: [table.placeId, table.boardType, table.date],
}),
})
);
import {
date,
pgEnum,
pgSchema,
primaryKey,
text,
varchar,
} from "drizzle-orm/pg-core";
export const place = public_db.table("place", {
placeId: varchar("place_id").notNull().primaryKey(),
state: varchar("state", { length: 2 }).notNull(),
county: text("county").notNull(),
city: text("city"),
createdAt: date("created_at").defaultNow(),
});
export const hearing = public_db.table(
"hearing",
{
placeId: varchar("place_id")
.notNull()
.references(() => place.placeId),
date: date("date").notNull(),
boardType: BoardType("board_type").notNull(),
commissioners: text("commissioners"),
createdAt: date("created_at").defaultNow(),
minutesFile: text("minutes_file"),
minutesFileTxt: text("minutes_file_txt"),
videoFile: text("video_file"),
transcriptFile: text("transcript_file"),
transcriptFileTxt: text("transcript_file_txt"),
},
(table) => ({
pk: primaryKey({
columns: [table.placeId, table.boardType, table.date],
}),
})
);
3 Replies
Here are some other errors I am experiencing. I'm feeling a version mismatch or something. Very hard to tell.
This error makes no sense:
Here, the following code compiles fine.
Something really weird going on.
those types are identical
WTF
ok, have confirmed one thing:
I do not get the type errors if i do the select in the same NPM package as i declare the schema
So, perhaps it's something to do with PNPM workspaces since I am consuming the schema from another pacakge
frontend/src/server/list-files.ts:51:24 - error TS2769: No overload matches this call.
Overload 1 of 3, '(left: Column<ColumnBaseConfig<ColumnDataType, string>, object, object>, right: unknown): SQL<unknown>', gave the following error.
Argument of type 'PgColumn<{ name: "state"; tableName: "place"; dataType: "string"; columnType: "PgVarchar"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>' is not assignable to parameter of type 'Column<ColumnBaseConfig<ColumnDataType, string>, object, object>'.
Types of property 'table' are incompatible.
Type 'PgTable<TableConfig>' is not assignable to type 'Table<TableConfig<Column<any, object, object>>>'.
Overload 2 of 3, '(left: Aliased<string>, right: string | SQLWrapper): SQL<unknown>', gave the following error.
Argument of type 'PgColumn<{ name: "state"; tableName: "place"; dataType: "string"; columnType: "PgVarchar"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>' is not assignable to parameter of type 'Aliased<string>'.
Type 'PgColumn<{ name: "state"; tableName: "place"; dataType: "string"; columnType: "PgVarchar"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>' is missing the following properties from type 'Aliased<string>': sql, fieldAlias
Overload 3 of 3, '(left: SQLWrapper, right: unknown): SQL<unknown>', gave the following error.
Argument of type 'PgColumn<{ name: "state"; tableName: "place"; dataType: "string"; columnType: "PgVarchar"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>' is not assignable to parameter of type 'SQLWrapper'.
Types of property 'getSQL' are incompatible.
Type '() => import("/Users/samgoodwin/workspaces/public.ai/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/drizzle-orm/sql/sql").SQL<unknown>' is not assignable to type '() => import("/Users/samgoodwin/workspaces/public.ai/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/drizzle-orm/sql/sql").SQL<unknown>'. Two different types with this name exist, but they are unrelated.
frontend/src/server/list-files.ts:51:24 - error TS2769: No overload matches this call.
Overload 1 of 3, '(left: Column<ColumnBaseConfig<ColumnDataType, string>, object, object>, right: unknown): SQL<unknown>', gave the following error.
Argument of type 'PgColumn<{ name: "state"; tableName: "place"; dataType: "string"; columnType: "PgVarchar"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>' is not assignable to parameter of type 'Column<ColumnBaseConfig<ColumnDataType, string>, object, object>'.
Types of property 'table' are incompatible.
Type 'PgTable<TableConfig>' is not assignable to type 'Table<TableConfig<Column<any, object, object>>>'.
Overload 2 of 3, '(left: Aliased<string>, right: string | SQLWrapper): SQL<unknown>', gave the following error.
Argument of type 'PgColumn<{ name: "state"; tableName: "place"; dataType: "string"; columnType: "PgVarchar"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>' is not assignable to parameter of type 'Aliased<string>'.
Type 'PgColumn<{ name: "state"; tableName: "place"; dataType: "string"; columnType: "PgVarchar"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>' is missing the following properties from type 'Aliased<string>': sql, fieldAlias
Overload 3 of 3, '(left: SQLWrapper, right: unknown): SQL<unknown>', gave the following error.
Argument of type 'PgColumn<{ name: "state"; tableName: "place"; dataType: "string"; columnType: "PgVarchar"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>' is not assignable to parameter of type 'SQLWrapper'.
Types of property 'getSQL' are incompatible.
Type '() => import("/Users/samgoodwin/workspaces/public.ai/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/drizzle-orm/sql/sql").SQL<unknown>' is not assignable to type '() => import("/Users/samgoodwin/workspaces/public.ai/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/drizzle-orm/sql/sql").SQL<unknown>'. Two different types with this name exist, but they are unrelated.
frontend/src/server/list-files.ts:50:16 - error TS2769: No overload matches this call.
Overload 1 of 3, '(left: Column<ColumnBaseConfig<ColumnDataType, string>, object, object>, right: unknown): SQL<unknown>', gave the following error.
Argument of type 'PgColumn<{ name: "place_id"; tableName: "hearing"; dataType: "string"; columnType: "PgVarchar"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>' is not assignable to parameter of type 'Column<ColumnBaseConfig<ColumnDataType, string>, object, object>'.
Types of property 'table' are incompatible.
Property '[IsDrizzleTable]' is missing in type 'PgTable<TableConfig>' but required in type 'Table<TableConfig<Column<any, object, object>>>'.
Overload 2 of 3, '(left: Aliased<PgColumn<{ name: "place_id"; tableName: "place"; dataType: "string"; columnType: "PgVarchar"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>>, right: SQLWrapper | PgColumn<...>): SQL<...>', gave the following error.
Argument of type 'PgColumn<{ name: "place_id"; tableName: "hearing"; dataType: "string"; columnType: "PgVarchar"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>' is not assignable to parameter of type 'Aliased<PgColumn<{ name: "place_id"; tableName: "place"; dataType: "string"; columnType: "PgVarchar"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>>'.
Type 'PgColumn<{ name: "place_id"; tableName: "hearing"; dataType: "string"; columnType: "PgVarchar"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>' is missing the following properties from type 'Aliased<PgColumn<{ name: "place_id"; tableName: "place"; dataType: "string"; columnType: "PgVarchar"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>>': sql, fieldAlias
Overload 3 of 3, '(left: SQLWrapper, right: unknown): SQL<unknown>', gave the following error.
Argument of type 'PgColumn<{ name: "place_id"; tableName: "hearing"; dataType: "string"; columnType: "PgVarchar"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>' is not assignable to parameter of type 'SQLWrapper'.
The types returned by 'getSQL()' are incompatible between these types.
Type 'import("/Users/samgoodwin/workspaces/public.ai/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/drizzle-orm/sql/sql").SQL<unknown>' is not assignable to type 'import("/Users/samgoodwin/workspaces/public.ai/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/drizzle-orm/sql/sql").SQL<unknown>'. Two different types with this name exist, but they are unrelated.
Types have separate declarations of a private property 'shouldInlineParams'.
50 eq(hearing.placeId, place.placeId),
~~~~~~~~~~~~~~~
node_modules/.pnpm/drizzle-orm@0.29.1_@neondatabase+serverless@0.6.0_postgres@3.4.3/node_modules/drizzle-orm/table.d.ts:29:5
29 [IsDrizzleTable]: boolean;
frontend/src/server/list-files.ts:50:16 - error TS2769: No overload matches this call.
Overload 1 of 3, '(left: Column<ColumnBaseConfig<ColumnDataType, string>, object, object>, right: unknown): SQL<unknown>', gave the following error.
Argument of type 'PgColumn<{ name: "place_id"; tableName: "hearing"; dataType: "string"; columnType: "PgVarchar"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>' is not assignable to parameter of type 'Column<ColumnBaseConfig<ColumnDataType, string>, object, object>'.
Types of property 'table' are incompatible.
Property '[IsDrizzleTable]' is missing in type 'PgTable<TableConfig>' but required in type 'Table<TableConfig<Column<any, object, object>>>'.
Overload 2 of 3, '(left: Aliased<PgColumn<{ name: "place_id"; tableName: "place"; dataType: "string"; columnType: "PgVarchar"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>>, right: SQLWrapper | PgColumn<...>): SQL<...>', gave the following error.
Argument of type 'PgColumn<{ name: "place_id"; tableName: "hearing"; dataType: "string"; columnType: "PgVarchar"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>' is not assignable to parameter of type 'Aliased<PgColumn<{ name: "place_id"; tableName: "place"; dataType: "string"; columnType: "PgVarchar"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>>'.
Type 'PgColumn<{ name: "place_id"; tableName: "hearing"; dataType: "string"; columnType: "PgVarchar"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>' is missing the following properties from type 'Aliased<PgColumn<{ name: "place_id"; tableName: "place"; dataType: "string"; columnType: "PgVarchar"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>>': sql, fieldAlias
Overload 3 of 3, '(left: SQLWrapper, right: unknown): SQL<unknown>', gave the following error.
Argument of type 'PgColumn<{ name: "place_id"; tableName: "hearing"; dataType: "string"; columnType: "PgVarchar"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>' is not assignable to parameter of type 'SQLWrapper'.
The types returned by 'getSQL()' are incompatible between these types.
Type 'import("/Users/samgoodwin/workspaces/public.ai/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/drizzle-orm/sql/sql").SQL<unknown>' is not assignable to type 'import("/Users/samgoodwin/workspaces/public.ai/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/drizzle-orm/sql/sql").SQL<unknown>'. Two different types with this name exist, but they are unrelated.
Types have separate declarations of a private property 'shouldInlineParams'.
50 eq(hearing.placeId, place.placeId),
~~~~~~~~~~~~~~~
node_modules/.pnpm/drizzle-orm@0.29.1_@neondatabase+serverless@0.6.0_postgres@3.4.3/node_modules/drizzle-orm/table.d.ts:29:5
29 [IsDrizzleTable]: boolean;
Type 'PgColumn<{ name: "state"; tableName: "place"; dataType: "string"; columnType: "PgVarchar"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>' is not assignable to type 'SQL<unknown> | Aliased<unknown> | PgColumn<ColumnBaseConfig<ColumnDataType, string>, {}, {}> | PgTable<TableConfig> | SelectedFieldsFlat<...>'
Type 'PgColumn<{ name: "state"; tableName: "place"; dataType: "string"; columnType: "PgVarchar"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>' is not assignable to type 'SQL<unknown> | Aliased<unknown> | PgColumn<ColumnBaseConfig<ColumnDataType, string>, {}, {}> | PgTable<TableConfig> | SelectedFieldsFlat<...>'
type A = PgColumn<
{
name: "state";
tableName: "place";
dataType: "string";
columnType: "PgVarchar";
data: string;
driverParam: string;
notNull: true;
hasDefault: false;
enumValues: [string, ...string[]];
baseColumn: never;
},
{},
{}
>;
type B = PgColumn<ColumnBaseConfig<ColumnDataType, string>, {}, {}>;
declare const a: A;
declare const b: B;
const c: B = a;
type A = PgColumn<
{
name: "state";
tableName: "place";
dataType: "string";
columnType: "PgVarchar";
data: string;
driverParam: string;
notNull: true;
hasDefault: false;
enumValues: [string, ...string[]];
baseColumn: never;
},
{},
{}
>;
type B = PgColumn<ColumnBaseConfig<ColumnDataType, string>, {}, {}>;
declare const a: A;
declare const b: B;
const c: B = a;
() => import("node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/drizzle-orm/sql/sql").SQL<unknown>' is not assignable to type '
() => import("node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/drizzle-orm/sql/sql").SQL<unknown>'.
Two different types with this name exist, but they are unrelated.
() => import("node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/drizzle-orm/sql/sql").SQL<unknown>' is not assignable to type '
() => import("node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/drizzle-orm/sql/sql").SQL<unknown>'.
Two different types with this name exist, but they are unrelated.
frontend/src/server/list-files.ts(91,23): error TS2769: No overload matches this call.
Overload 1 of 3, '(left: Column<ColumnBaseConfig<ColumnDataType, string>, object, object>, right: unknown): SQL<unknown>', gave the following error.
Argument of type 'PgColumn<{ name: "city"; tableName: "place"; dataType: "string"; columnType: "PgText"; data: string; driverParam: string; notNull: false; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>' is not assignable to parameter of type 'Column<ColumnBaseConfig<ColumnDataType, string>, object, object>'.
Types of property 'table' are incompatible.
Type 'PgTable<TableConfig>' is not assignable to type 'Table<TableConfig<Column<any, object, object>>>'.
frontend/src/server/list-files.ts(91,23): error TS2769: No overload matches this call.
Overload 1 of 3, '(left: Column<ColumnBaseConfig<ColumnDataType, string>, object, object>, right: unknown): SQL<unknown>', gave the following error.
Argument of type 'PgColumn<{ name: "city"; tableName: "place"; dataType: "string"; columnType: "PgText"; data: string; driverParam: string; notNull: false; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>' is not assignable to parameter of type 'Column<ColumnBaseConfig<ColumnDataType, string>, object, object>'.
Types of property 'table' are incompatible.
Type 'PgTable<TableConfig>' is not assignable to type 'Table<TableConfig<Column<any, object, object>>>'.
Type 'PgTable<TableConfig>' is not assignable to type 'Table<TableConfig<Column<any, object, object>>>'
Type 'PgTable<TableConfig>' is not assignable to type 'Table<TableConfig<Column<any, object, object>>>'
frontend
-> database
have confirmed the problem happens in a PNPM workspace, even if you ensure all versions of drizzle-orm
the same, peer dependencies, etc.
typescript gets confused and thinks there are two packages instead of 1
seems to really hinge around the use of unique symbols but i am not sure
I can workaround this problem by moving everything into a single package and re-exporting drizzle-orm/pg-core from that. This ensures there's only one version of drizzle-orm installed.
But I am left very confused: this used to work. Only after doing a clean build did i find the problem.
I suspect something fucky with my config.Try looking at the tsconfig.json
Check this issue, this person had a similiar problem, might help you find the issue: https://github.com/drizzle-team/drizzle-orm/issues/1558
GitHub
[BUG]: Splitting database schemas into a separate package in monore...
What version of drizzle-orm are you using? 0.29.0 What version of drizzle-kit are you using? 0.20.4 (but not relevant) Describe the Bug Copy/paste the example drizzle adapter code from https://gith...