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)

Most upvoted comments

I’m afraid I am also in the same boat, I have a model such as:

model Answer {
  id String @id @default(cuid())
  question Question @relation(fields: [questionId], references: [id], onDelete: Cascade)
  questionId String
}

but then trying to create a record in this model like:

create(questionId: string, input: AnswerInput) {
  return this.prisma.answer.create({
     data: {
      ...input,
      questionId,
    },
  });
}

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:

model Job {
  id Int @id @default(autoincrement())
  type JobType
  createdAt DateTime @default(now())
  date DateTime
  price Float 
  priceType PriceType @default(WHOLE)
  currency Currency @default(RSD)
  userId Int
  user   User @relation(fields: [userId], references: [id])

  @@map("jobs")
}

DTO:

export class CreateJobDto {
  @IsString()
  @IsNotEmpty()
  name: string;

  @IsEnum(JobType)
  @IsNotEmpty()
  type: string;

  @IsDate()
  @IsNotEmpty()
  date: Date;

  @IsNotEmpty()
  @IsNumber()
  price: number;

  @IsEnum(Currency)
  @IsNotEmpty()
  currency: string;

  @IsNotEmpty()
  @IsEnum(PriceType)
  priceType: string;
}

Where the error is happening:

 async createJob(userId: number, jobDto: CreateJobDto) {
    const job = await this.prisma.job.create({
      data: { ...jobDto, userId},
    });
  }

It is not letting me assign userId because it says that the types are incompatible, more accurately:

Types of property 'userId' are incompatible.
        Type 'number' is not assignable to type 'never'

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:

input AnswerInput {
  text: String!
  correct: Boolean = False
}

I was expecting this to be converted to:

export class AnswerInput {
  text: string;
  correct: boolean | false;
}

it was in reality converted to:

export class AnswerInput {
  text: string;
  correct?: Nullable<boolean>;
}

The combination of which with questionId: string made TypeScript complain, the fix for me was to change my service method to:

create(questionId: string, input: AnswerInput) {
  const { text, correct = false } = input;

  return this.prisma.answer.create({
    data: {
      correct,
      text,
      questionId,
    },
  });
}

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 AnswerInput I 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

Someone would need to reproduce first, so if you can give us more information, that would help.

For which field do you get Type 'string' is not assignable to type 'never'? Is there any extra info about this error? For example, where it comes from?

Could you give us an example of the data passed in prisma.candidaturas.create({ data: candidatura }); (candidatura)

The camp with Type 'string' is not assignable to type 'never' is the ownerID, and the type of candidatura is the class of the first message of this issues, and sorry for the delay to response