mongoosejs / mongoose-lean-getters

Apply getters on lean() documents: https://mongoosejs.com/docs/tutorials/lean.html
Apache License 2.0
10 stars 15 forks source link

empty index.ts causing TypeScript or runtime error #15

Closed iammola closed 2 years ago

iammola commented 2 years ago

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

What is the current behaviour? This error is caused by the empty index.ts file you added in https://github.com/mongoosejs/mongoose-lean-getters/pull/14, when I delete the file and reload extensions, I can import the plugin without any errors.

I import this way

import mongooseLeanGetters from "mongoose-lean-getters";

And I get this TypeScript error

File '/Users/~/node_modules/mongoose-lean-getters/index.ts' is not a module.ts(2306)

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

With my TSConfig try and import the module

{
  "compilerOptions": {
    "allowJs": true,
    "allowSyntheticDefaultImports": true,
    "baseUrl": ".",
    "paths": { "*": ["*", "src/*"] },
    "downlevelIteration": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "incremental": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "lib": ["dom", "dom.iterable", "esnext"],
    "module": "esnext",
    "moduleResolution": "node",
    "noEmit": true,
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "sourceMap": true,
    "strict": true,
    "target": "esnext"
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "**/*.js"],
  "exclude": ["node_modules", ".next", "out"]
}

I also noticed in the index.d.ts, there's a TypeScript error in there as well

declare module 'mongoose-lean-getters' {
  import mongoose = require('mongoose');
  export default function mongooseLeanGetters(schema: mongoose.Schema<any, any, any, any>, opts?: any): void; // Generic type 'Schema<T>' requires between 0 and 1 type arguments.ts(2707)

  export function mongooseLeanGetters(schema: mongoose.Schema<any, any, any, any>, opts?: any): void; // Generic type 'Schema<T>' requires between 0 and 1 type arguments.ts(2707)

}

Screenshot of index.d.ts TS error

What is the expected behaviour? To import the module without any errors.

What are the versions of Node.js, mongoose-lean-getters, and Mongoose are you are using? Note that "latest" is not a version. Node.JS - v17.8.0 mongoose-lean-getters - v0.3.2 Mongoose - v6.3.1

iammola commented 2 years ago

I went to where the mongoose.Schema it used was defined, and it lead me to a folder with typescript caches in them /Users/~/Library/Caches/typescript for multiple versions. I've deleted them now and the errors in the index.d.ts are no more.

But I still cant import the plugin