Closed
Description
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
Mongoose version
8.0.0
Node.js version
20.0.0
MongoDB server version
6.0
Typescript version (if applicable)
latest
Description
The inferred return type for distinct()
queries with an array fields is incorrect. It's inferred to be string[][]
for a string[]
field when in fact it should be string[]
Steps to Reproduce
interface Foo {
bar: string[];
}
const FooModel = model<Foo>('Foo', new Schema<Foo>({ bar: [String] }));
await FooModel.create({ bar: ['a', 'b'] })
const distinctBar = await FooModel.distinct('bar');
console.log(distinctBar); // [ 'a', 'b' ]
distinctBar
is actually a string[]
but the inferred return type is string[][]
.
Expected Behavior
Inferred return type does not add Array
to a type which is already an Array