#How to debug "has or is using private identifier"?

3 messages · Page 1 of 1 (latest)

cold hazel
#

So I have a rather complicated setup which is conceptually available in this codesandbox and fully available on gitlab.

The gist of it is this: I'm using

namespace Module {
  export class Foo {}
  export namespace Foo {
    interface ForExtension {}
  }
}
declare global {
  export import Foo = Module.Foo
}

to make both the class and the merged namespace available in the global namespace. I'm doing that so that consumers of my library can put their own values in the ForExtension interface, similar to how HTMLElementTagNameMap and such work.

The interesting thing is, that this works in one instance, doesn't in another and the codesandbox tells me that export import isn't even allowed in augmentations... but that error never appears in my local environment? Same tsconfig and typescript version 🤔

So yeah, no idea how to proceed from here, how do I even begin to debug this?

P.s.: if you have a better idea on how to make a class and a namespace globally available, I'm all ears. Have been trying around with this for close to a year now...

cold hazel
#

and now I can't reproduce any error even in a simplified repo?!?!? This getting weirder and weirder, is typescript using some cache I don't know of?

cold hazel
#

okay, found the reason. With --declaration the namespace Module is empty in the .d.ts file, which means that any reference to Module.Foo can't be resolved. The solution is to "explicitly" refer to globalThis.Foo instead of just Foo for modules that are dependencies of multiple augmentations of the same interface. No idea why that works though.

See here for more info about the use case