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

Typescript: Internal types use Date instead of NativeDate - bug? #10426

Closed
kfiroo opened this issue Jul 7, 2021 · 1 comment
Closed

Typescript: Internal types use Date instead of NativeDate - bug? #10426

kfiroo opened this issue Jul 7, 2021 · 1 comment
Labels
typescript Types or Types-test related issue / Pull Request
Milestone

Comments

@kfiroo
Copy link

kfiroo commented Jul 7, 2021

Hey!

Trying to implement custom timestamps.currentTime as described in the docs

My simplified implementation looks like this:

const thingSchema = new mongoose.Schema({
  //...
}, {
  timestamps: {
    currentTime: () => new Date()
  } 
});

I get the following TS error:

TS2322: Type 'Date' is not assignable to type 'number | Date'.
  Type 'Date' is not assignable to type 'number'.

After some investigation it looks like there might be some confusion with the NativeDate and Date types.

For instance, I would expect mongoose.now to return NativeDate and not Date
Same for mongoose.SchemaTimestampsConfig.currentTime.

mongoose version 5.13.2

tsconfig.json

{
  "compilerOptions": {
    "target": "ES2019",
    "module": "commonjs",
    "moduleResolution": "node",
    "outDir": "dist",
    "skipLibCheck": true,
    "allowJs": true,
    "esModuleInterop": true,
    "noImplicitAny": true,
    "experimentalDecorators":true,
    "emitDecoratorMetadata": true,
    "strictFunctionTypes": true,
    "sourceMap": true,
    "lib": [
      "ESNext"
    ]
  },
  ...
}
@IslandRhythms IslandRhythms added the typescript Types or Types-test related issue / Pull Request label Jul 7, 2021
@vkarpov15 vkarpov15 added this to the 5.13.3 milestone Jul 11, 2021
@vkarpov15
Copy link
Collaborator

Fixed in 5edb25d, I typo-ed the issue number in the commit message.

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