Skip to content

mongoose has assignability error after #42248 #42337

@sandersn

Description

@sandersn

To repro: cd DefinitelyTyped/types/mongoose && tsc; observe that there are 74 errors, 2 more than the expected 72.

const locationSchema = new mongoose.Schema({
  name: { type: String, required: true },
  address: String,
  rating: { type: Number, "default": 0, min: 0, max: 5 },
  facilities: [String],
  coords: { type: [Number], index: "2dsphere" },
  openingTimes: [mongoose.Schema.Types.Mixed],
  reviews: [mongoose.SchemaTypes.Mixed],
  notes: [noteSchema]
});
var LocModel = mongoose.model<Location>("Location", locationSchema);
LocModel.create({ address: "foo", coords: [1, 2], facilities: ["foo", "bar"], name: "bar", openingTimes: ["foo"], rating: 10, reviews: ["foo"], notes: [] });

Actual:

At mongoose/test/model.ts:613, errors on openingTimes and reviews:

ERROR: 613:107  expect  TypeScript@4.2 compile error: 
No overload matches this call.
  The last overload gave the following error.
    Type 'string' is not assignable to type 'never'.
      Type 'string' is not assignable to type 'never'.

Expected: No error; the input type was [mongoose.SchemeTypes.Mixed], which should result in string[] not never[]

Likely related to #42336, although in this case we can't ship with this error in mongoose, which may involve fixing mongoose in some way.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions