Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema definition Types error when property type is an array of another schema #9962

Closed
ahmednaser94 opened this issue Feb 22, 2021 · 0 comments
Labels
typescript Types or Types-test related issue / Pull Request
Milestone

Comments

@ahmednaser94
Copy link

Do you want to request a feature or report a bug?
bug

What is the current behavior?
the schema definition must match EXACTLY as the interface in case of array

image

It does not complain when it is array like this, but if it was an object with type: [HistoryUpdateRecordSchema] it gives type error!!

image

Type '{ type: Schema<HistoryUpdateRecord & Document<any>, Model<HistoryUpdateRecord & Document<any>>, HistoryUpdateRecord>[]; default: undefined; }' is not assignable to type 'SchemaDefinitionProperty<Pick<Pick<_LeanDocument<HistoryUpdateRecord>, "fieldName" | "oldValue" | "newValue">, "fieldName" | "oldValue" | "newValue">[]>'.
  Types of property 'type' are incompatible.
    Type 'Schema<HistoryUpdateRecord & Document<any>, Model<HistoryUpdateRecord & Document<any>>, HistoryUpdateRecord>[]' is not assignable to type 'string | Function | Pick<Pick<_LeanDocument<HistoryUpdateRecord>, "fieldName" | "oldValue" | "newValue">, "fieldName" | "oldValue" | "newValue">[]'.
      Type 'Schema<HistoryUpdateRecord & Document<any>, Model<HistoryUpdateRecord & Document<any>>, HistoryUpdateRecord>[]' is not assignable to type 'Pick<Pick<_LeanDocument<HistoryUpdateRecord>, "fieldName" | "oldValue" | "newValue">, "fieldName" | "oldValue" | "newValue">[]'.
        Type 'Schema<HistoryUpdateRecord & Document<any>, Model<HistoryUpdateRecord & Document<any>>, HistoryUpdateRecord>' is missing the following properties from type 'Pick<Pick<_LeanDocument<HistoryUpdateRecord>, "fieldName" | "oldValue" | "newValue">, "fieldName" | "oldValue" | "newValue">': fieldName, oldValue, newValue

If the current behavior is a bug, please provide the steps to reproduce.

https://gist.github.com/ahmednaser94/5a6288614fa29eea30f15a7ee1a42a22


{
  "compilerOptions": {
    "target": "ES6",
    "module": "CommonJS",
    "outDir": "dist",
    "removeComments": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "resolveJsonModule": true,
    "moduleResolution": "Node",
    "sourceMap": true,
    "typeRoots": ["@types", "./node_modules/@types"]
  },
  "include": ["src"],
  "exclude": ["test", "node_modules"]
}

What is the expected behavior?
It should not complain about type as any other property

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.

"typescript": "^4.1.5",
 "mongodb": "^3.6.4",
 "mongoose": "^5.11.17",
@ahmednaser94 ahmednaser94 changed the title Schema definition Types error when property type is array of another schema Schema definition Types error when property type is an array of another schema Feb 22, 2021
@IslandRhythms IslandRhythms added typescript Types or Types-test related issue / Pull Request has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue labels Feb 22, 2021
@vkarpov15 vkarpov15 added this to the 5.11.19 milestone Feb 23, 2021
@vkarpov15 vkarpov15 removed the has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue label Mar 5, 2021
This was referenced Mar 5, 2021
This was referenced Mar 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
typescript Types or Types-test related issue / Pull Request
Projects
None yet
Development

No branches or pull requests

3 participants