You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched existing issues to ensure the bug has not already been reported
Mongoose version
8.1.2
Node.js version
18.x
MongoDB server version
4.2.8
Typescript version (if applicable)
No response
Description
When using the distinct query for nested fields, the declared type of the return value is unknown[], even though the type should be statically discoverable as string[].
Type 'unknown[]' is not assignable to type 'string[]'
Steps to Reproduce
I've included some sample code above. It's written in the style of nestjs, so it may need to be modified a bit for a simpler use case without nestjs.
Create a document schema with a subdocument.
Write a distinct query for the document on one of the nested fields on the subdocument.
The specified return type will be unknown[]
Expected Behavior
The resolved return type should be an array of the subdocument field type. In this case, string[].
The text was updated successfully, but these errors were encountered:
bpabel
changed the title
Type is incorrect when for Query.distinct when field is a nested field
Type is incorrect for Query.distinct when field is a nested field
May 24, 2024
Confirmed that this is an issue. We'll investigate and see if we can fix this. In the meantime, you can add a type override as follows to prevent this compiler error.
Prerequisites
Mongoose version
8.1.2
Node.js version
18.x
MongoDB server version
4.2.8
Typescript version (if applicable)
No response
Description
When using the
distinct
query for nested fields, the declared type of the return value isunknown[]
, even though the type should be statically discoverable asstring[]
.A minimal example
myrecord.schema.ts
myrecord.service.ts
The type checking error shows:
Type 'unknown[]' is not assignable to type 'string[]'
Steps to Reproduce
I've included some sample code above. It's written in the style of nestjs, so it may need to be modified a bit for a simpler use case without nestjs.
distinct
query for the document on one of the nested fields on the subdocument.unknown[]
Expected Behavior
The resolved return type should be an array of the subdocument field type. In this case,
string[]
.The text was updated successfully, but these errors were encountered: