prisma: Type 'string' is not assignable to type 'never'
Bug description
For some reason i’m getting the Type 'string' is not assignable to type 'never' error, but the variables are with same tipe (string)
How to reproduce
prisma.< database >.<create || update>({ data: <data> })
Prisma information
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
model Users {
id String @id @unique
firstName String
lastName String
email String @unique
password String
number Int
curriculo String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
anuncios Anuncios[]
candidaturas Candidaturas[]
}
model Anuncios {
id String @id @unique
ownerID String
companyName String
local String
description String @db.VarChar(500)
salary String?
role String
typeJob String // Remoto, presencial ou híbrido
requirements String? @db.VarChar(500)
contractType String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
owner Users @relation(fields: [ownerID], references: [id])
candidaturas Candidaturas[]
}
model Candidaturas {
id String @id @unique
ownerID String
anuncioID String
status Int @default(0) //0 - nenhuma atualização, 1 - aceito, 2 - recusado, 3 - Em analise
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
owner Users @relation(fields: [ownerID], references: [id])
anuncio Anuncios @relation(fields: [anuncioID], references: [id])
}
async create(candidatura: Candidaturas): Promise<Candidaturas> {
return this.prisma.candidaturas.create({ data: candidatura });
}
Candidaturas.ts:
import { v4 as uuid } from 'uuid';
import Users from './Users';
import Anuncios from './Anuncios';
class Candidaturas {
public readonly id: string;
public readonly ownerID: string;
public readonly anuncioID: string;
public status?: number;
public createdAt: Date;
public updatedAt: Date;
public readonly owner?: Users;
public readonly anuncio?: Anuncios;
constructor(props: Omit<Candidaturas, 'id' | 'createdAt' | 'updatedAt'>, id?: string) {
Object.assign(this, props);
if (!id) {
this.id = uuid();
}
}
}
export default Candidaturas;
Environment & setup
- OS: Windows11
- Database: mysql
- Node.js version: v16.16.0
Prisma Version
prisma : 4.5.0
@prisma/client : 4.5.0
Current platform : windows
Query Engine (Node-API) : libquery-engine 0362da9eebca54d94c8ef5edd3b2e90af99ba452 (at node_modules\@prisma\engines\query_engine-windows.dll.node)
Migration Engine : migration-engine-cli 0362da9eebca54d94c8ef5edd3b2e90af99ba452 (at node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine : introspection-core 0362da9eebca54d94c8ef5edd3b2e90af99ba452 (at node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary : prisma-fmt 0362da9eebca54d94c8ef5edd3b2e90af99ba452 (at node_modules\@prisma\engines\prisma-fmt-windows.exe)
Format Wasm : @prisma/prisma-fmt-wasm 4.5.0-43.0362da9eebca54d94c8ef5edd3b2e90af99ba452
Default Engines Hash : 0362da9eebca54d94c8ef5edd3b2e90af99ba452
Studio : 0.476.0
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 3
- Comments: 35 (6 by maintainers)
I’m afraid I am also in the same boat, I have a model such as:
but then trying to create a record in this model like:
My create function complains about
Type 'string' is not assignable to type 'never', I have multiple other models that follow the same pattern but this is the only model where this problem exits, also fwiw this is the final model in my schema not sure if that’s somehow related.I am running a nestjs with latest prisma and engine is postgres, is there something I can provide to demystify this? I tried adding strict to tsconfig but that didnt change anything, the tsconfig file provided by nest already has some configs that may be in conflict with strict
Hello everyone, I am facing the same problem but with different data
Model:
DTO:
Where the error is happening:
It is not letting me assign userId because it says that the types are incompatible, more accurately:
EDIT: For whatever reason, Dev Environment was signalling me that userId is incompatible while the problem was in other fields that were incomatible, namely the ones that were supposed to be Enums were not consolidated between my class and DTO, when I fixed that, the error was gone
Yes, you can consider it fixed. I will add the explanation here as soon as I have some free time. Thanks, @EnriqueVidal
@janpio the data of table is: id, status, createdAt, updatedAt, ownerID, anuncioID ‘dc667d1b-796a-4821-b2ef-7581326e2edf’, ‘0’, ‘2022-11-19 17:09:32.933’, ‘2022-11-19 17:09:32.933’, ‘548095e2-bd83-4028-89aa-e6f016031e53’, ‘ae7cb90d-db65-460c-bcd3-fde0bbef9a7c’
@borjapazr and @DiogoMarques2003 I just managed to resolve this with the help of someone in the nestjs discord, the problem was a little tricky to figure out as I never thoguht to check the generated types of converting my graphql SDL into typescript, it turns out that while my input type was written like:
I was expecting this to be converted to:
it was in reality converted to:
The combination of which with
questionId: stringmade TypeScript complain, the fix for me was to change my service method to:If it wasn’t for @xxninjabunnyxx (hope I tagged the correct person) at discord that actually tried by inlining the type I would have never tought to check the generated type for
AnswerInputI hope the issue you’re having is this simple to fix as well, cheers.If you made changes to your schema run “npx prisma generate”
same issue – with upsert
any update @janpio ? If you need the source code with this problem is one this repository: https://github.com/DiogoMarques2003/portugal-jobs/tree/main/Backend
The camp with
Type 'string' is not assignable to type 'never'is theownerID, and the type ofcandidaturais the class of the first message of this issues, and sorry for the delay to response