InvalidTypeError: Type is invalid! Type is: "undefined"

See original GitHub issue

Versions

  • typegoose: 7.3.0
  • mongoose: 5.9.24
'''

Using the following definition for UserClass:

@pre<UserClass>("save", async function (next: HookNextFunction): Promise<void> {
    ...
})
@index({ name: 1 }, { collation: { locale: "en", strength: 1 }, unique: true })
export class UserClass {
    @prop({
        required: true,
        trim: true,
        unique: true,
        minlength: 3,
        maxlength: 20
    })
    public name!: string;
...
}

I get the following unhelpful error:

@typegoose\typegoose\lib\internal\processProp.js:160
        throw new errors_1.InvalidTypeError(name, key, Type);
        ^

InvalidTypeError: "UserClass.name"'s Type is invalid! Type is: "undefined"
    at Object.processProp (C:\Users\winterNebs\source\repos\AscensionGame\AscensionGame\node_modules\@typegoose\typegoose\lib\internal\processProp.js:160:15)
    at Object._buildSchema (C:\Users\winterNebs\source\repos\AscensionGame\AscensionGame\node_modules\@typegoose\typegoose\lib\internal\schema.js:37:27)
    at buildSchema (C:\Users\winterNebs\source\repos\AscensionGame\AscensionGame\node_modules\@typegoose\typegoose\lib\typegoose.js:120:20)
    at Object.getModelForClass (C:\Users\winterNebs\source\repos\AscensionGame\AscensionGame\node_modules\@typegoose\typegoose\lib\typegoose.js:70:39)
    at Object../database/schema/user.ts (C:\Users\winterNebs\source\repos\AscensionGame\AscensionGame\dist\app.js:2121:28)
    at __webpack_require__ (C:\Users\winterNebs\source\repos\AscensionGame\AscensionGame\dist\app.js:20:30)
    at Object../gameAppServer.ts (C:\Users\winterNebs\source\repos\AscensionGame\AscensionGame\dist\app.js:2409:16)
    at __webpack_require__ (C:\Users\winterNebs\source\repos\AscensionGame\AscensionGame\dist\app.js:20:30)
    at Object../app.ts (C:\Users\winterNebs\source\repos\AscensionGame\AscensionGame\dist\app.js:1351:25)
    at __webpack_require__ (C:\Users\winterNebs\source\repos\AscensionGame\AscensionGame\dist\app.js:20:30)
    at C:\Users\winterNebs\source\repos\AscensionGame\AscensionGame\dist\app.js:84:18
    at Object.<anonymous> (C:\Users\winterNebs\source\repos\AscensionGame\AscensionGame\dist\app.js:87:10)
    at Module._compile (internal/modules/cjs/loader.js:955:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
    at Module.load (internal/modules/cjs/loader.js:811:32)
    at Function.Module._load (internal/modules/cjs/loader.js:723:14)

As far as I can tell the type for name is string, not undefined. Can anyone spot what I did wrong or is this error not related to this code?

I migrated from ts-mongoose since that project doesn’t look like its being updated anymore, so sorry that I don’t have a very minimal example.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

74reactions
JohnDevedcommented, Jul 16, 2020

encountering the same issue right now. setting "emitDecoratorMetadata": true in the tsconfig.json fixed it for me

3reactions
JMPJNScommented, Aug 7, 2020

for people using babel instead of tsc, this plugin also fixes it

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error & Warning Details - typegoose
Error: Prop-Option "ref"'s value is "null" or "undefined" for "${name}. ... This Error may get thrown when a invalid Type is used with...
Read more >
Error: "User.email"'s Type is invalid! Type is: "undefined" ...
In your tsconfig file uncomment this line: "emitDecoratorMetadata": true /* Emit design-type metadata for decorated declarations in source ...
Read more >
Failed schema validation after insert with sdk's becuase of ...
hi, After I insert a new Realm-Object via SDK (Swift or Java) that contains a null value I run into a schema validation...
Read more >
Extending Schemas — marshmallow 3.19.0 documentation
__envelope__["single"] assert key is not None, "Envelope key undefined" return key @pre_load(pass_many=True) ... "type": "Custom invalid type error message.
Read more >
Found template literal expression having a non-string type
Invalid type "never" of template literal expression. src/repository.ts. 1345 } 1346 1347 if (!(item.stats.birthtime instanceof Date)) { 1348 throw new ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found