question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Types] properties like "caster" are not typed (SingleNestedPath)

See original GitHub issue

Do 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 extends EventEmitter
  • path should be typed
  • base should be typed
  • when possible '$isSingleNested' should also be typed

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

1reaction
vkarpov15commented, Jul 28, 2021

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.

0reactions
hasezoeycommented, Jul 11, 2021

that might be true, so what is schema.path() and schema.eachPath(the second parameter from the callback) supposed to be

and just to clarify, with subdocument-schematype you mean Schema.Types.* and with actual-subdocuments you mean Types.*? when yes, them i am mixing things up maybe, but if not, look at the reproduction code i provided, it clearly logs the output from schema.eachPath (both parameters) and it contained those values / functions on the output

Read more comments on GitHub >

github_iconTop 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 >

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