1

I am trying to export mongoose.Types in two different ways so that I can access it in another file to create interfaces or types. Why does 1 approach work and the other one doesn't? E.g

❌ This doesn't work:

helper.ts:

import mongoose from "mongoose";
export default { types: mongoose.Types }

main.ts

import helper from "./helper"
export interface Admin {
  userId: helper.types.ObjectId
}

& throws this error: 🚫 Cannot find namespace 'helper'.ts(2503), while as this works perfectly: ✅

helper.ts:

import mongoose from "mongoose";
export default mongoose.Types;

main.ts

import helper from "./helper"
export interface Admin {
  userId: helper.ObjectId
}

Incase you don't know, mongoose.Types is a namespace. Is there any particular way of handling import/export of namespaces. What exactly is happening here?

4
  • You're treating mongoose.Types as if it's a type when it's a namespace. Export types not namespaces. Commented Jan 23, 2022 at 17:13
  • Are namespaces exportable? Commented Jan 23, 2022 at 17:36
  • What you are trying to do doesn't make any sense. If you want to export types, export types, not the namespace. Commented Jan 23, 2022 at 17:48
  • May be I was not articulate enough in phrasing my problem. I just updated my question, kindly go through it once again & you'll understand what I am actually struggling with. Thanks. Commented Jan 23, 2022 at 20:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.