Cannot find namespace - ts(2503) [Exporting a namespace]

2.9k views Asked by At

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?

0

There are 0 answers