nestjs/mongoose

SchemaOptions TypeKey

Shikakka opened this issue · 0 comments

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

When assigning the option typeKey to a Schema decorator it gives the following warning.

(property) SchemaOptions<"type", unknown, {}, {}, {}, {}>.typeKey?: "type" | undefined
By default, if you have an object with key 'type' in your schema, mongoose will interpret it as a type declaration. However, for applications like geoJSON, the 'type' property is important. If you want to control which key mongoose uses to find type declarations, set the 'typeKey' schema option.

Type '"$type"' is not assignable to type '"type"'.ts(2322)

Minimum reproduction code

https://gist.github.com/Shikakka/e3ceef24128d63b7b40368cd9ed7c518

Steps to reproduce

No response

Expected behavior

Apply the typeKey correctly, like the Mongoose package itself does. Using $type as the typeKey:

(alias) new MongooseSchema<any, Model<any, any, any, any, any>, {}, {}, any, {}, "$test", {
    type?: string | undefined;

Package version

9.1.1

mongoose version

6.4.1

NestJS version

8.4.7

Node.js version

16.15.1

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

It is a change done in the Mongoose package itself. Previously typeKey was typed as a string. In one of the later versions they changed it.
April 20th vs Change