Closed NightRare closed 2 years ago
Run npx tsc filename.ts and then node ./filename.js to confirm second section runtime error
uncomment line 2 and comment line 3 to confirm first section error
comment untyped schema and line 2 and uncomment typed Schema and line 3 to confirm last section error.
import * as mongoose from 'mongoose';
// import * as mongooseLeanGetters from 'mongoose-lean-getters';
import mongooseLeanGetters from 'mongoose-lean-getters';
interface Test {
name: string
}
const testSchema = new mongoose.Schema({
name: String
});
/*
const testSchema = new mongoose.Schema<Test>({
name: String
});
*/
testSchema.plugin(mongooseLeanGetters);
We fixed this in #14 . You'll be able to do both import mongooseLeanGetters from 'mongoose-lean-getters'
and import { mongooseLeanGetters } from 'mongoose-lean-getters'
In
index.d.ts
the function is exported as the default while inindex.js
it is exported as the module. This causes the following error when trying toimport * as mongooseLeanGetters from 'mongoose-lean-getters'
:import mongooseLeanGetters from 'mongoose-lean-getters'
resolves this error. However it will cause a runtime error as the function was actually not the default. In addition, it might cause another TypeScript error for the reason mentioned in the following item.The mongoose.Schema type takes type arguments and if the type arguments are specified it will trigger a TypeScript error when doing
schema.plugin(mongooseLeanGetters)
as there is no type arguments specified on schema infunction mongooseLeanGetters(schema: mongoose.Schema): void;
Thanks.