mongoosejs / mongoose-long

Provides Number Long support for Mongoose
MIT License
77 stars 16 forks source link

Serialization error when working with TypeScript #20

Open dhwanik-speed opened 1 year ago

dhwanik-speed commented 1 year ago

Getting error - error TS4118: The type of this node cannot be serialized because its property '[hasInstance]' cannot be serialized. when using TypeScript.

Example model:

import mongoose, { Schema } from "mongoose";
import mongooseLong from "mongoose-long";

mongooseLong(mongoose);

const { Decimal128, Long } = Schema.Types;

const ExchangeSchema = new Schema({
  timestamp: Long,
  meta: [{
    timestamp: Long,
    pair: String,
    _id: false
  }],
  rates: {
    type: Map,
    of: Decimal128,
  },
  conversion_rate_fetch_timestamp: Long,
}, {
  timestamps: true,
});

Version information: mongodb: ^5.2.0 mongoose: ^6.3.4 mongoose-long: ^0.6.0 typescript: ^4.7.2

Any help/workarounds are appreciated. Thanks!

IslandRhythms commented 1 year ago

image I'm getting a different error

dhwanik-speed commented 1 year ago

You need to install mongodb package through NPM for it to work

IslandRhythms commented 1 year ago

image I do have it installed

IslandRhythms commented 1 year ago

image Running it anyway causes this

NewEraCracker commented 3 weeks ago

Are you sure you've followed this https://github.com/mongoosejs/mongoose-long?tab=readme-ov-file#typescript-usage ?

Make sure you enable both compilerOptions.allowSyntheticDefaultImports and compilerOptions.esModuleInterop in your tsconfig.json.