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

Types break in semver patch change #14462

Open
2 tasks done
Anonymous4078 opened this issue Mar 23, 2024 · 6 comments
Open
2 tasks done

Types break in semver patch change #14462

Anonymous4078 opened this issue Mar 23, 2024 · 6 comments
Labels
can't reproduce Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity. Stale typescript Types or Types-test related issue / Pull Request

Comments

@Anonymous4078
Copy link

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.2.3

Node.js version

20.11.1

MongoDB server version

5.x

Typescript version (if applicable)

5.4.3

Description

› yarn build
Error: src/listeners/message/messageBulkDelete.ts(28,49): error TS2769: No overload matches this call.
  Overload [1](https://github.com/Anonymous4078/suggester/actions/runs/8382964808/job/22957771088?pr=327#step:6:1) of [4](https://github.com/Anonymous4078/suggester/actions/runs/8382964808/job/22957771088?pr=327#step:6:5), '(filter?: FilterQuery<GuildConfig> | undefined, projection?: ProjectionType<GuildConfig> | null | undefined, options?: QueryOptions<...> | ... 1 more ... | undefined): Query<...>', gave the following error.
    Type 'string | null' is not assignable to type 'Condition<string> | undefined'.
      Type 'null' is not assignable to type 'Condition<string> | undefined'.
  Overload 2 of 4, '(filter?: FilterQuery<GuildConfig> | undefined, projection?: ProjectionType<GuildConfig> | null | undefined): Query<...>', gave the following error.
    Type 'string | null' is not assignable to type 'Condition<string> | undefined'.
  Overload 3 of 4, '(filter?: FilterQuery<GuildConfig> | undefined): Query<(Document<unknown, {}, GuildConfig> & GuildConfig & { _id: ObjectId; }) | null, Document<...> & ... 1 more ... & { ...; }, {}, GuildConfig, "findOne">', gave the following error.
    Type 'string | null' is not assignable to type 'Condition<string> | undefined'.
Error: src/listeners/message/messageBulkDelete.ts(32,1[5](https://github.com/Anonymous4078/suggester/actions/runs/8382964808/job/22957771088?pr=327#step:6:6)): error TS2322: Type 'string | null' is not assignable to type 'Condition<string> | undefined'.
Error: src/listeners/message/messageDelete.ts(21,45): error TS2769: No overload matches this call.
  Overload 1 of 4, '(filter?: FilterQuery<GuildConfig> | undefined, projection?: ProjectionType<GuildConfig> | null | undefined, options?: QueryOptions<...> | ... 1 more ... | undefined): Query<...>', gave the following error.
    Type 'string | null' is not assignable to type 'Condition<string> | undefined'.
  Overload 2 of 4, '(filter?: FilterQuery<GuildConfig> | undefined, projection?: ProjectionType<GuildConfig> | null | undefined): Query<...>', gave the following error.
    Type 'string | null' is not assignable to type 'Condition<string> | undefined'.
  Overload 3 of 4, '(filter?: FilterQuery<GuildConfig> | undefined): Query<(Document<unknown, {}, GuildConfig> & GuildConfig & { _id: ObjectId; }) | null, Document<...> & ... 1 more ... & { ...; }, {}, GuildConfig, "findOne">', gave the following error.
    Type 'string | null' is not assignable to type 'Condition<string> | undefined'.
Error: src/listeners/message/messageDelete.ts(25,[11](https://github.com/Anonymous4078/suggester/actions/runs/8382964808/job/22957771088?pr=327#step:6:12)): error TS2322: Type 'string | null' is not assignable to type 'Condition<string> | undefined'.
Error: Process completed with exit code 1.

My code used to work till v8.2.2 and types suddenly broke with 8.2.3

Steps to Reproduce

await collection.findOneAndUpdate(
            { guildId },
            {
              $pull: { suggestions: { messageId: message.id } },
            },
          );

Expected Behavior

The types shouldn't break in a semver patch change

@vkarpov15 vkarpov15 added this to the 8.2.5 milestone Mar 29, 2024
@vkarpov15 vkarpov15 added needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue typescript Types or Types-test related issue / Pull Request labels Mar 29, 2024
@Anonymous4078
Copy link
Author

Needs a fix

@vkarpov15
Copy link
Collaborator

@Anonymous4078 what does your schema look like?

@Anonymous4078
Copy link
Author

@vkarpov15 Simple schema which break is :

import { Schema, model } from 'mongoose';

interface GuildConfig {
  guildId: string;
  channelIds: string[];
}

const schema = new Schema<GuildConfig>({
  guildId: String,
  channelIds: [String],
});

export const collection = model<GuildConfig>('cooldowns', schema);

@Anonymous4078
Copy link
Author

Worked perfectly fine till version 8.2.2 and breaks in v8.2.3

@vkarpov15
Copy link
Collaborator

I'm unable to repro, the following script compiles fine:

import { Schema, model } from 'mongoose';

interface GuildConfig {
  guildId: string;
  channelIds: string[];
}

const schema = new Schema<GuildConfig>({
  guildId: String,
  channelIds: [String],
});

const collection = model<GuildConfig>('cooldowns', schema);

const guildId = '42';
collection.findOneAndUpdate(
            { guildId },
            {
              $pull: { channelIds: 'test' },
            },
          );

output:

$ ./node_modules/.bin/tsc --strict gh-14462.ts 
$ 
$ head ./node_modules/typescript/package.json 
{
    "name": "typescript",
    "author": "Microsoft Corp.",
    "homepage": "https://www.typescriptlang.org/",
    "version": "5.4.3",
    "license": "Apache-2.0",
    "description": "TypeScript is a language for application scale JavaScript development",
    "keywords": [
        "TypeScript",
        "Microsoft",
$ head ./node_modules/mongoose/package.json 
{
  "name": "mongoose",
  "description": "Mongoose MongoDB ODM",
  "version": "8.3.0",
  "author": "Guillermo Rauch <guillermo@learnboost.com>",
  "keywords": [
    "mongodb",
    "document",
    "model",
    "schema",
$ 

@vkarpov15 vkarpov15 added can't reproduce Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity. and removed needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue labels Apr 10, 2024
@vkarpov15 vkarpov15 removed this from the 8.3.2 milestone Apr 10, 2024
Copy link

This issue is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 5 days

@github-actions github-actions bot added the Stale label Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
can't reproduce Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity. Stale typescript Types or Types-test related issue / Pull Request
Projects
None yet
Development

No branches or pull requests

2 participants