Skip to content

Typescript error with type mixed #10900

Closed
@israelKusayev

Description

@israelKusayev

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

What is the current behavior?

Getting typescript error when using Mixed type

export interface IPatient {
  birthday?: string | Date;
}

export const patientSchema = new Schema<IPatient>({
  birthday: {
    type: SchemaTypes.Mixed
  }
});

Type '{ type: typeof Schema.Types.Mixed; }' is not assignable to type 'SchemaDefinitionProperty<string | Date>'. Types of property 'type' are incompatible. Type 'typeof Mixed' is not assignable to type '"string" | StringConstructor | "String" | typeof String | typeof NativeDate | "date" | "Date" | typeof Date'. Type 'typeof Mixed' is missing the following properties from type 'StringConstructor': fromCharCode, fromCodePoint, rawts(2322)

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

tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "target": "es6",
    "noImplicitAny": true,
    "moduleResolution": "node",
    "sourceMap": true,
    "outDir": "dist",
    "baseUrl": ".",
    "paths": {
      "*": ["node_modules/*", "src/types/*"]
    }
  },
  "include": ["src/**/*"]
}

What is the expected behavior?

Mixed should behave as any type (sometimes I can't use mongoose types but I still want to use typescript types

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

Mongoose 6.0.11
typescript 4.4.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    typescriptTypes or Types-test related issue / Pull Request

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions