[Types] properties like "caster" are not typed (SingleNestedPath)
See original GitHub issueDo you want to request a feature or report a bug? types
What is the current behavior? the options are un-typed
If the current behavior is a bug, please provide the steps to reproduce.
// NodeJS: 16.4.1
// MongoDB: 4.2-bionic (Docker)
import * as mongoose from "mongoose"; // mongoose@5.13.2
const schema1 = new mongoose.Schema({ nestedPath1: { prop1: String } });
const schema2 = new mongoose.Schema({ nestedSchema: schema1 });
// @ts-ignore
console.log("schema1.nestPath1", schema1.path("nestedPath1"));
// @ts-ignore
console.log("schema2.nestedSchema", schema2.path("nestedSchema").caster);
// tslint-disable no-unused
schema2.eachPath((path, type) => {
console.log("path,type", path, type);
if (type instanceof mongoose.Schema.Types.Embedded) {
// currently an error everywhere from typescript "property does not exist"
type.caster;
type.emit;
type.on;
type.path;
type.base;
}
});
What is the expected behavior? the properties to be typed
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that “latest” is not a version. mongoose: 5.13.2
options to do:
-
mongoose.Schema.Types.Embedded
should extendsEventEmitter
-
path
should be typed -
base
should be typed - when possible
'$isSingleNested'
should also be typed
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:5
Top Results From Across the Web
Document Missing Property when not using lean() · Issue #8615
Do you want to request a feature or report a bug? bug. What is the current behavior? I have a simple schema. var...
Read more >Typescript and Mongoose: Property 'x' does not exist on type ...
So we have to write them out as typescript types. interface UserDocument extends Document { id: number; name: string; email: string ...
Read more >Mongoose v6.8.2: API docs
Type : «property». The Mongoose ObjectId SchemaType. Used for declaring paths in your schema that should be MongoDB ObjectIds. Do not use this...
Read more >Argument of type '{ useNewUrlParser: boolean ... - MongoDB
This is the error: Type '{ useNewUrlParser: boolean; useUnifiedTopology: boolean; }' has no properties in common with type 'MongoClientOptions'.
Read more >Mongoose API v4.4.14
When no collection argument is passed, Mongoose produces a collection name by passing the model name to the utils.toCollectionName method.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
schema.path()
returns the subdocument schematype, e.g.instanceof mongoose.Schema.Types.Embedded
.And yes, the subdocument schematype does have those properties, but they’re not meant to be user-facing. If there’s a reason for them to be user facing I’m happy to add them to the TS bindings.
that might be true, so what is
schema.path()
andschema.eachPath
(the second parameter from the callback) supposed to beand just to clarify, with subdocument-schematype you mean
Schema.Types.*
and with actual-subdocuments you meanTypes.*
? when yes, them i am mixing things up maybe, but if not, look at the reproduction code i provided, it clearly logs the output fromschema.eachPath
(both parameters) and it contained those values / functions on the output