Visitar URL original
Module augmentation seems to break when namespace and class have same name Β· Issue #52933 Β· microsoft/TypeScript Β· GitHub
The Wayback Machine - https://web.archive.org/web/20230307162210/https://github.com/microsoft/TypeScript/issues/52933
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module augmentation seems to break when namespace and class have same name #52933

Closed
entropitor opened this issue Feb 23, 2023 · 2 comments
Closed
Labels
Bug A bug in TypeScript Good First Issue Well scoped, documented and has the green light Help Wanted You can do this
Milestone

Comments

@entropitor
Copy link

Bug Report

πŸ”Ž Search Terms

Module Augmentation
Namespace
Class
Same name
Jupyterlab

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries

⏯ Playground Link

Doesn't work because it's about module augmentation.

πŸ’» Code

// index.ts
    import {CodeMirrorEditor} from '@jupyterlab/codemirror';
    const newEditor = new CodeMirrorEditor({
      config: {
        myExtraOption: true,
      },
      host: {} as any,
      model: {} as any,
    });

The above fails because myExtraOption is an option not officially in @jupyterlab/codemirror.

However, when I add

// jupyterlab-codemirror.d.ts
import '@jupterlab/codemirror';

declare module '@jupyterlab/codemirror' {
  declare namespace CodeMirrorEditor {
    interface IConfig {
      myExtraOption: boolean;
    }
  }
}

it starts failing instead with

typescript: Cannot use namespace 'CodeMirrorEditor' as a value. [2708]

it seems that the declaration file somehow starts shadowing the class CodeMirrorEditor which is also in @jupyterlab/codemirror

πŸ™ Actual behavior

Declaration merging is hiding the class

πŸ™‚ Expected behavior

The namespace is extended while the class is still visible

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this labels Feb 23, 2023
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Feb 23, 2023
@RyanCavanaugh RyanCavanaugh added the Good First Issue Well scoped, documented and has the green light label Feb 23, 2023
@egonSchiele
Copy link

egonSchiele commented Mar 5, 2023 •

@entropitor , I can't reproduce this issue. Could you clone this repo and see if you still get the issue? It's a react app that includes @ jupyterlab/codemirror (I took a guess at how your code is structured). The code matches your code above (see here for example).

I also created a simpler version that doesn't include codemirror or react. I have a module animals here, which exports a class and a namespace, both with the same name. The namespace includes an interface. I then augment the interface in that namespace here. Here I use the augmented interface, and it works fine.

My guess is you are somehow importing CodeMirrorEditor the namespace instead of CodeMirrorEditor the class.

As a side note, I didn't see a test covering this specific type of declaration merging. Should I add a mergedDeclarations8 similar to this test?

@entropitor
Copy link
Author

Yeah, it seems that on the latest version, it's not reproducible. Sorry for bothering you 😭

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Good First Issue Well scoped, documented and has the green light Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

3 participants