Argument of type 'SQL<unknown>' is not assignable to parameter
I have the following:
and the
What could be the problem?
const projects = await db
.select()
.from(project)
.where(eq(project.ownerId, userId));
const projects = await db
.select()
.from(project)
.where(eq(project.ownerId, userId));
eq()
gives an error like:
Argument of type 'SQL<unknown>' is not assignable to parameter of type 'SQL<unknown> | ((aliases: { id: MySqlColumn<{ data: string; driverParam: string | number; notNull: true; hasDefault: true; tableName: "Project"; }>; name: MySqlColumn<{ data: string; driverParam: string | number; hasDefault: false; notNull: true; tableName: "Project"; }>; description: MySqlColumn<...>; createdAt: My...'.
Type 'Name' is not assignable to type 'Chunk'.
Property 'encoder' is missing in type 'Name' but required in type 'Param<unknown, unknown>'.ts(2345)
index.d.ts(80, 14): 'encoder' is declared here.
Argument of type 'SQL<unknown>' is not assignable to parameter of type 'SQL<unknown> | ((aliases: { id: MySqlColumn<{ data: string; driverParam: string | number; notNull: true; hasDefault: true; tableName: "Project"; }>; name: MySqlColumn<{ data: string; driverParam: string | number; hasDefault: false; notNull: true; tableName: "Project"; }>; description: MySqlColumn<...>; createdAt: My...'.
Type 'Name' is not assignable to type 'Chunk'.
Property 'encoder' is missing in type 'Name' but required in type 'Param<unknown, unknown>'.ts(2345)
index.d.ts(80, 14): 'encoder' is declared here.
5 Replies
This is a weird one. Could you post your tsconfig.json?
Sure!
The root one:
The db package has:
and the server package:
Here's the tsc log:
Sorry bout the formatting 🙂
{
"compilerOptions": {
"target": "es2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"noUncheckedIndexedAccess": true,
"paths": {
"@/*": [
"./*"
]
}
},
"include": [".eslintrc.cjs"]
}
{
"compilerOptions": {
"target": "es2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"noUncheckedIndexedAccess": true,
"paths": {
"@/*": [
"./*"
]
}
},
"include": [".eslintrc.cjs"]
}
{
"extends": "../../tsconfig.json",
"include": [
"./**/*.ts"
]
}
{
"extends": "../../tsconfig.json",
"include": [
"./**/*.ts"
]
}
{
"extends": "../../tsconfig.json",
"include": ["src", "index.ts", "transformer.ts"]
}
{
"extends": "../../tsconfig.json",
"include": ["src", "index.ts", "transformer.ts"]
}
@dcmnt/api:type-check: > @dcmnt/[email protected] type-check /Users/nn/Code/mm/dcmnt/packages/api
@dcmnt/api:type-check: > tsc --noEmit
@dcmnt/api:type-check:
@dcmnt/api:type-check: src/service/project.ts(27,12): error TS2345: Argument of type 'SQL<unknown>' is not assignable to parameter of type 'SQL<unknown> | ((aliases: { id: MySqlColumn<{ data: string; driverParam: string | number; notNull: true; hasDefault: true; tableName: "Project"; }>; name: MySqlColumn<{ data: string; driverParam: string | number; hasDefault: false; notNull: true; tableName: "Project"; }>; description: MySqlColumn<...>; createdAt: My...'.
@dcmnt/api:type-check: Type 'import("/Users/nn/Code/mm/dcmnt/node_modules/drizzle-orm/sql/index").SQL<unknown>' is not assignable to type 'import("/Users/nn/Code/mm/dcmnt/packages/db/node_modules/drizzle-orm/sql/index").SQL<unknown>'.
@dcmnt/api:type-check: Types of property 'queryChunks' are incompatible.
@dcmnt/api:type-check: Type 'import("/Users/nn/Code/mm/dcmnt/node_modules/drizzle-orm/sql/index").Chunk[]' is not assignable to type 'import("/Users/nn/Code/mm/dcmnt/packages/db/node_modules/drizzle-orm/sql/index").Chunk[]'.
@dcmnt/api:type-check: Type 'import("/Users/nn/Code/mm/dcmnt/node_modules/drizzle-orm/sql/index").Chunk' is not assignable to type 'import("/Users/nn/Code/mm/dcmnt/packages/db/node_modules/drizzle-orm/sql/index").Chunk'.
@dcmnt/api:type-check: Type 'Name' is not assignable to type 'Chunk'.
@dcmnt/api:type-check: Property 'encoder' is missing in type 'Name' but required in type 'Param<unknown, unknown>'.
@dcmnt/api:type-check: ELIFECYCLE Command failed with exit code 2.
@dcmnt/api:type-check: ERROR: command finished with error: command (/Users/nn/Code/mm/dcmnt/packages/api) pnpm run type-check exited (1)
@dcmnt/api:type-check: > @dcmnt/[email protected] type-check /Users/nn/Code/mm/dcmnt/packages/api
@dcmnt/api:type-check: > tsc --noEmit
@dcmnt/api:type-check:
@dcmnt/api:type-check: src/service/project.ts(27,12): error TS2345: Argument of type 'SQL<unknown>' is not assignable to parameter of type 'SQL<unknown> | ((aliases: { id: MySqlColumn<{ data: string; driverParam: string | number; notNull: true; hasDefault: true; tableName: "Project"; }>; name: MySqlColumn<{ data: string; driverParam: string | number; hasDefault: false; notNull: true; tableName: "Project"; }>; description: MySqlColumn<...>; createdAt: My...'.
@dcmnt/api:type-check: Type 'import("/Users/nn/Code/mm/dcmnt/node_modules/drizzle-orm/sql/index").SQL<unknown>' is not assignable to type 'import("/Users/nn/Code/mm/dcmnt/packages/db/node_modules/drizzle-orm/sql/index").SQL<unknown>'.
@dcmnt/api:type-check: Types of property 'queryChunks' are incompatible.
@dcmnt/api:type-check: Type 'import("/Users/nn/Code/mm/dcmnt/node_modules/drizzle-orm/sql/index").Chunk[]' is not assignable to type 'import("/Users/nn/Code/mm/dcmnt/packages/db/node_modules/drizzle-orm/sql/index").Chunk[]'.
@dcmnt/api:type-check: Type 'import("/Users/nn/Code/mm/dcmnt/node_modules/drizzle-orm/sql/index").Chunk' is not assignable to type 'import("/Users/nn/Code/mm/dcmnt/packages/db/node_modules/drizzle-orm/sql/index").Chunk'.
@dcmnt/api:type-check: Type 'Name' is not assignable to type 'Chunk'.
@dcmnt/api:type-check: Property 'encoder' is missing in type 'Name' but required in type 'Param<unknown, unknown>'.
@dcmnt/api:type-check: ELIFECYCLE Command failed with exit code 2.
@dcmnt/api:type-check: ERROR: command finished with error: command (/Users/nn/Code/mm/dcmnt/packages/api) pnpm run type-check exited (1)
Ah, there's the issue - you have two different vesions of Drizzle in different folders, and try to use them both in a same file
/Users/nn/Code/mm/dcmnt/packages/db/node_modules/drizzle-orm/sql/index
/Users/nn/Code/mm/dcmnt/node_modules/drizzle-orm/sql/index
Thanks! I'll try to fix that, thought of it as well but the versions in package.json's were the same, so thought they resolved to the same.
If you have a monorepo, you should probably hoist the Drizzle dependency for all packages to reuse the same one