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

Type of Date not correct on typescript schemas #10409

Closed
fi6 opened this issue Jul 1, 2021 · 0 comments
Closed

Type of Date not correct on typescript schemas #10409

fi6 opened this issue Jul 1, 2021 · 0 comments
Labels
typescript Types or Types-test related issue / Pull Request
Milestone

Comments

@fi6
Copy link

fi6 commented Jul 1, 2021

Do you want to request a feature or report a bug?
Bug
What is the current behavior?
Date in interface and schema are not compatible for Date.
If the current behavior is a bug, please provide the steps to reproduce.

interface Something {
    field: Date;
}
const someSchema = new Schema<Something, Model<Something>, Something>({
    field: {type: Date}
})

error:
Types of property 'type' are incompatible.
Type 'DateConstructor' is not assignable to type 'Date | typeof SchemaType | Schema<any, any, undefined, unknown> | undefined'.
Type 'DateConstructor' is missing the following properties from type 'typeof SchemaType': cast, checkRequired, set, get.

However if using field: {type: Date} as unknown as Date it works.

"compilerOptions": {
    "declaration": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "rootDir": "./src",
    "target": "es2018",
    "module": "commonjs",
    "moduleResolution": "node",
    "lib": ["es2018"],
    "outDir": "./dist",
    "strict": true,
    "baseUrl": "./src/",
    "typeRoots": ["./typings", "node_modules/@types"],
    "esModuleInterop": true,
    "sourceMap": true,
    "skipLibCheck": true
},
"include": ["./src/**/*.ts"],
"exclude": ["./src/test", "./src/backup", "node_modules"]

What is the expected behavior?
Should not raise the error
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Mongoose: 5.13.0

@IslandRhythms IslandRhythms added the typescript Types or Types-test related issue / Pull Request label Jul 1, 2021
@vkarpov15 vkarpov15 added this to the 5.13.2 milestone Jul 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
typescript Types or Types-test related issue / Pull Request
Projects
None yet
Development

No branches or pull requests

3 participants