Typegoose: [Question] Type is invalid error

Created on 22 Sep 2019  路  7Comments  路  Source: typegoose/typegoose

Hi @hasezoey , thanks for maintaining this project

I just refactored a project to use Typegoose instead of just Mongoose. I'm using the 6.0 "next" version on NPM. But when I start my server, I get this error:

Error: "undefined.users"'s Type is invalid! Type is: "undefined"

The error is quite vague, and it's hard to know where it comes from, especially since I just made a lot of changes. All I know is that users is one of my collections.

Is it introspecting my database to see if it matches the generated schema ? Did I mess up a prop() ?

Thanks

question

Most helpful comment

could you do a minimal repo script?

Update: try to update to 6.0.0-30, this should fix the "undefined.users" verify that it is "Brand"

Another Update: could you try setting itemsRef: User to itemsRef: "User"?
-> when this solved it, please read here on why it is so

All 7 comments

The error is quite vague,

i actually tried to make the errors as "not vague" as possible, it is in the format of "Class.Property"

so it means:

  1. your class is given as undefined (or the name is just got wrong, happens sometimes)
  2. the Type of "users" is not a correct type (typegoose found the type as "undefined")

for more help i would need the model it errors on, and sorry for the wrong stacktrace, this is because of DEO (#23,#24)

Thanks for the quick response.

I thought it was a problem with my User model, but since the users in the error message is a property, I found that it comes from another model (Brand) that has a users property. It's a reference to the User model.

Here's how it's defined:

class Brand {
  // Other props above

  @arrayProp({ itemsRef: User })
  users: Ref<User>[]
}
const BrandModel = getModelForClass(Brand)

where User is a class with @prop attributes from another file.

Removing the users attribute from the Brand gets rid of the error, but how can I actually fix this ?

could you do a minimal repo script?

Update: try to update to 6.0.0-30, this should fix the "undefined.users" verify that it is "Brand"

Another Update: could you try setting itemsRef: User to itemsRef: "User"?
-> when this solved it, please read here on why it is so

You nailed it:

  • I updated to version 30 and it confirmed the error came from the Brand model
  • Setting the ref as a string fixed the error

Thanks for the help!

Unrelated: I noticed the repo changed ownership, so you should change the link to the Github pages site in the repo's description

Unrelated: I noticed the repo changed ownership, so you should change the link to the Github pages site in the repo's description

i will, once i release version 6.0.0, for now github just redirects to here :)

so, this issue is solved now? when yes you can close this

This issue is back at 7.0.0

@ChrisLahaye please open a new issue with reproduction code

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AbderrazzakB picture AbderrazzakB  路  3Comments

kerolloz picture kerolloz  路  6Comments

DanielEberl picture DanielEberl  路  5Comments

akash-rajput picture akash-rajput  路  4Comments

vobence picture vobence  路  8Comments