Model named "Key" is incorrectly typed
See original GitHub issueBug description
I have a model called Key
. When I run prisma generate
and try to use the TypeScript types, the type for Key
is incorrect. Looking at the generated TS file, I see two Key
types.
I don’t see these in the reserved word list: https://github.com/prisma/prisma/blob/master/src/packages/client/src/generation/generateClient.ts#L368
How to reproduce
- Setup Prisma with the supplied schema.
- Look at the TS types
- Notice the TS type for the
Key
model is incorrect.
Expected behavior
There should not be a TS error.
If that’s not possible, maybe throw an error when using reserved words like Key
or count
.
Prisma information
model Key {
id Int @id
name String? @db.VarChar(45)
AnotherTable AnotherTable[]
}
model AnotherTable {
id Int @id @default(autoincrement())
keyId Int
Key Key @relation(fields: [keyId], references: [id])
@@index([keyId], name: "fk_AnotherTable_Key_idx")
}
When I run prisma generate
and try to use the TypeScript types, the type for Key
is incorrect.
type TResponse = Prisma.AnotherTableGetPayload<{
include: {
Key: true;
};
}>
const obj: TResponse = {
id: 4,
Key: { id: 4, name: 'name' }
};
When I mouse over Key
, I get the following:
(property) Key: Prisma.Key
Type '{ id: number; name: string; }' is not assignable to type 'Key'.
Type '{ id: number; name: string; }' is not assignable to type 'symbol'.ts(2322)
Looking at the generated TS file, I see two Key
types.
...
/**
* Model Key
*/
export type Key = {
id: number
name: string | null
}
...
export namespace Prisma {
...
type Key = string | number | symbol;
...
}
Below has been fixed by 2.23.0
.
Incidentally, as I was writing this description, I updated the Prisma version to the latest and ran into another similar error with a column named count
. The generated TS file looked like this:
export type ExerciseGroupByOutputType = {
id: number
count: number | null
count: ExerciseCountAggregateOutputType | null
avg: ExerciseAvgAggregateOutputType | null
sum: ExerciseSumAggregateOutputType | null
min: ExerciseMinAggregateOutputType | null
max: ExerciseMaxAggregateOutputType | null
}
I got the following errors:
error TS2300: Duplicate identifier 'count'.
error TS2717: Subsequent property declarations must have the same type. Property 'count' must be of type 'number | null', but here has type 'ExerciseCountAggregateOutputType | null'.
Environment & setup
- OS: Mac OS
- Database: MySQL
- Node.js version: v15.10.0
Prisma Version
2.22.1
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
I can confirm this
Key
issue.Yes, you are looking at the issue tracking it. Compared to other problems this is not important enough to be prioritized right now though. Sorry.