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

Global namespaces from script files and module files via declare global considered different #2774

Closed
blutorange opened this issue Nov 13, 2024 · 1 comment
Labels
enhancement Improved functionality
Milestone

Comments

@blutorange
Copy link

blutorange commented Nov 13, 2024

Search Terms

declaration merging declare global script module

Problem

(Yeah, I know, globals again. I would also like to use modules, but that's hard to impossible for large existing projects. primefaces/primefaces#12717)

When you have a global script file (without import / export) and a module file that both amend a namspace in the global scope, typedoc seems to consider these as different.

When using the plugin typedoc-plugin-merge-modules, that results in the namespaces not getting merged. But I think the issue is not with the plugin, as it seems to happen even without the plugin. For example:

// base.ts
namespace PrimeFaces {
  export interface WindowExtensions{}
}
interface Window extends PrimeFaces.WindowExtensions {}

// src/a.ts
import "./module.js"; // make this a module file
declare global {
  namespace PrimeFaces {
    export interface WindowExtensions{
      a: string;
    }
  }
}

// src/b.ts
// similar a.ts

// src/c.ts
namespace PrimeFaces {
  export interface WindowExtensions{
    c: string;
  }
}

// src/d.ts
// similar to c.ts

// index.ts
console.log(window.a, window.b, window.c, window.d);

Now when generate docs from that, d/PrimeFaces is marked as a re-export of c/PrimeFaces. But a/PrimeFaces and b/PrimeFaces are not and contain only a and b, respectively. Interestingly enough though, c/PrimeFaces contains all of a, b, c and d.

image

With typedoc-plugin-merge-modules, that then results in duplicates:

image

Repro

git clone https://github.com/blutorange/primefaces-js-refactor-test.git
cd primefaces-js-refactor-test/
git checkout demo-typedoc-merge-script-module
yarn install
yarn tsc # note that this compiles, so all interfaces point to the same thing
yarn typedoc  --out docs src/index.ts src/a.ts src/b.ts src/c.ts src/d.ts src/module.ts
open docs/index.html
@blutorange blutorange added the enhancement Improved functionality label Nov 13, 2024
@Gerrit0 Gerrit0 added this to the v0.27.0 milestone Nov 15, 2024
@Gerrit0 Gerrit0 closed this as completed Nov 15, 2024
@blutorange
Copy link
Author

Just to let you know, I Just checked out your commit, seems to be working nicely in our case. 👍

Before there were multiple namespaces

image

Now they're replaced with nice references:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improved functionality
Projects
None yet
Development

No branches or pull requests

2 participants