Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expression produces a union type that is too complex to represent. #499

Closed
harveyconnor opened this issue Mar 2, 2021 · 8 comments
Closed
Labels
bug Something isn't working cant reproduce The current reproduce script does not work info needed Extra information is needed stale This Issue | PR had no activity in a while and will be closed if it stays so

Comments

@harveyconnor
Copy link

harveyconnor commented Mar 2, 2021

Hi I'm getting the error: Expression produces a union type that is too complex to represent.. I get the error when I call the .create() method on a model.
These are my versions:

  • Typescript: 4.2.2
  • @typegoose/typegoose: 7.5.0
  • @types/mongoose: 5.10.3
  • mongoose: 5.10.18

This is stopping me from getting any type definitions for my models so everything is as if I'm coding in plain js..

@harveyconnor harveyconnor added the bug Something isn't working label Mar 2, 2021
@hasezoey hasezoey added the info needed Extra information is needed label Mar 2, 2021
@hasezoey
Copy link
Member

hasezoey commented Mar 2, 2021

could you give an code example?

@ezracelli
Copy link

@hasezoey I'm also running into this error on TModel.create() call (playground link here):

import { ObjectId } from "bson";
import { getModelForClass, prop as Property } from "@typegoose/typegoose";

export class User {
    readonly _id?: ObjectId;

    @Property({ required: true, type: () => Date })
    createdAt!: Date;

    @Property({ type: () => Date })
    deletedAt!: Date | null;

    @Property({ required: true })
    email!: string;

    @Property({ required: true, type: () => Date })
    updatedAt!: Date;

    @Property({ required: true })
    username!: string;

    @Property({ required: true })
    password!: string;
}

export const UserModel = getModelForClass(User);

UserModel.create({
    createdAt: new Date(),
    deletedAt: null,
    email: "",
    updatedAt: new Date(),
    username: "",
    password: "",
})

Output:

error TS2590: Expression produces a union type that is too complex to represent.

@hasezoey
Copy link
Member

@ezracelli does the error still appear when using the right ObjectId type that is mongoose.Types.ObjectId?

and what versions are you using:

  • typescript
  • typegoose
  • mongoose
  • @types/mongoose (if used)

@ezracelli
Copy link

@hasezoey Yep, unfortunately the error persists when using mongoose.Types.ObjectId. Here's my (truncated) package.json:

{
  "dependencies": {
    "@typegoose/typegoose": "^7.6.0",
    "bson": "^4.3.0",
    "mongoose": "5.10.18"
  },
  "devDependencies": {
    "@types/mongoose": "^5",
    "typescript": "^4.2.4"
  }
}

Should I be pinning @types/mongoose to a specific version as well?

@hasezoey
Copy link
Member

sorry for the late reply, but i cannot reproduce this problem

Code Used
// NodeJS: 16.1.0
// MongoDB: 4.2-bionic (Docker)
import { getModelForClass, prop } from "@typegoose/typegoose"; // @typegoose/typegoose@7.6.0
import * as mongoose from "mongoose"; // mongoose@5.10.18 @types/mongoose@5.10.5

export class User {
  public readonly _id?: mongoose.Types.ObjectId;

  @prop({ required: true, type: () => Date })
  public createdAt!: Date;

  @prop({ type: () => Date })
  public deletedAt!: Date | null;

  @prop({ required: true })
  public email!: string;

  @prop({ required: true, type: () => Date })
  public updatedAt!: Date;

  @prop({ required: true })
  public username!: string;

  @prop({ required: true })
  public password!: string;
}

export const UserModel = getModelForClass(User);

(async () => {
  await mongoose.connect(`mongodb://localhost:27017/`, { useNewUrlParser: true, dbName: "verifyMASTER", useCreateIndex: true, useUnifiedTopology: true });

  const doc = await UserModel.create({
    createdAt: new Date(),
    deletedAt: null,
    email: "y",
    updatedAt: new Date(),
    username: "y",
    password: "y",
  });

  console.log(doc);

  await mongoose.disconnect();
})();

Reproduction repo: https://github.com/typegoose/typegoose-testing/tree/verify499

@hasezoey hasezoey added the cant reproduce The current reproduce script does not work label May 27, 2021
@hasezoey
Copy link
Member

@harveyconnor @ezracelli does this issue still persist in typegoose 8.3 or typegoose 9.0 beta?

@harveyconnor
Copy link
Author

@hasezoey Hi we haven't migrated yet, just been using it without typings

@hasezoey hasezoey added the stale This Issue | PR had no activity in a while and will be closed if it stays so label Jun 5, 2022
@github-actions github-actions bot removed the stale This Issue | PR had no activity in a while and will be closed if it stays so label Jun 5, 2022
@hasezoey hasezoey added the stale This Issue | PR had no activity in a while and will be closed if it stays so label Jun 26, 2022
@github-actions github-actions bot removed the stale This Issue | PR had no activity in a while and will be closed if it stays so label Jun 26, 2022
@hasezoey hasezoey added the stale This Issue | PR had no activity in a while and will be closed if it stays so label Jun 26, 2022
@github-actions github-actions bot removed the stale This Issue | PR had no activity in a while and will be closed if it stays so label Jun 26, 2022
@hasezoey hasezoey added the stale This Issue | PR had no activity in a while and will be closed if it stays so label Dec 22, 2022
@hasezoey
Copy link
Member

Closing this issue because it is stale (for quite a long time), i had kept this open until now because of actions/stale#766 to have a issue to test with

@hasezoey hasezoey closed this as not planned Won't fix, can't repro, duplicate, stale Dec 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cant reproduce The current reproduce script does not work info needed Extra information is needed stale This Issue | PR had no activity in a while and will be closed if it stays so
Projects
None yet
Development

No branches or pull requests

3 participants