-
Notifications
You must be signed in to change notification settings - Fork 719
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
How to document custom elements without too many hacks #2844
Comments
the way I read this this would only help if I wanted to document something that isn't exported. The problem/behaviour I'm seeing however is, that as soon as anything is exported the global definitions are completely omitted. Now the answer could ofc simply be to not export anything, but sometimes I do want to export stuff from a module, e.g. types to enable consumer plugins. Also, this plugin would not help with the documentation on the merged |
I'm not sure what you mean by that. If the type is being referenced it should be included.
AFAIK, nope. I'd use @module for extra docs |
Also, why are you adding documentation inside the
|
TypeDoc expects to document exports, support for globals is tenuous at best, and every globals-based setup seems to want something slightly different and likely incompatible with the last globals user...
Yes, if an entry point uses exports, TypeDoc expects those exports to fully describe the module.
That doesn't sound right. The only way that the element gets defined once is that the file must have been imported at some point... and ignoring hot reload nastiness, modules should only be defined once. (hot reload I'd expect to also break in the same way, so that can't be the issue...) I'm guessing you're doing the side effects in each module to make it possible to import part of your module... I'd be very tempted to use normal imports/exports everywhere and do the global augmentation in one place so that normal exports could be used to define what is documented.
That didn't seem right to me, I checked on it and realized that TypeDoc was treating members as external if any declarations were external, with c372df3 that's changed, so it should show up now. With no exported members from the example file, the current dev branch produces this now (I duplicated |
because it shouldn't be exported :) You don't have to import
Well I feel you and I would also have liked if CEs weren't class based. Alas, this is the way to extend the definition of the available element tags :/
fair enough, but it's also not working as I would hope (not even expect) if the export keyword is within the global declarations
This can easily happen if a module can be consumed in multiple ways - e.g. when including a bundled version and then accidentally importing the exported class directly.
no, the module should be an ambient import, nothing else. Any and all values and types should be accessible from the global object.
hmmm, that sounds like it might save me some pain, I'll have a look at whether that's possible. The thing is though, that when using libraries to define custom elements people might not even be able to separate the augmentation from the definition...
nice, so that just leaves the awkward way to declare global classes? I'll try it out in a sec, is this published already or should I install a git dependency? |
this is looking a lot better with the mentioned commit, thank you. However, there are still some "issues", with the following module (and some existing modules around it, sorry for that) import { customElement } from "simple-custom-elements";
namespace Module {
/**
* a test CE
*/
@customElement({ tagname: "my-ce" })
export class MyCe extends HTMLElement {}
}
declare global {
namespace globalThis {
export import MyCe = Module.MyCe;
}
namespace MyCe {
/**
* an example aug
*/
export type Foo = number;
}
interface HTMLElementTagNameMap {
/**
* the my-ce element
*/
"my-ce": MyCe;
}
}
In any way, thank you for your quick answer |
That isn't a module export, which is what TypeDoc looks for, TypeDoc asks the compiler what a file exports, it doesn't walk the entire syntax tree manually (it used to, ~4 years ago, and that was a nightmare, every single TS release broke things, and it never worked quite right)
In my opinion, that's a bug in the consuming code! They should either use a bundled version and not import your code at all, or import your code and let their bundler include it. Including a module twice and expecting it to play together with another opens up all sorts of problems...
This doesn't happen in my setup... so it must be getting augmented somewhere, if you have
This is a design limitation. There is only one global symbol, so if you're going to document globals, you should only have one entry point. This is another problem with globals -- there is no reasonable way to determine which entry point they should belong to in the case of there being multiple entry points. You could technically probably work around this by creating a separate tsconfig for each module, running TypeDoc on each module separately, and then merging the results together, but that's going to be horribly slow and likely still not produce good results. |
So I'm not sure what the differences are yet but I created a quick demo repo and with the current dev branch this works nearly as intended. Just two nits:
|
found another issue: https://gitlab.com/hesxenon/ce-docs-how-to/-/blob/main/lib/my-ce.ts#L20 produces: the first link only links to the namespace, the second link works. I think that the link resolution stops after a qualifier... (btw, are the docs there out of date? tsdoc seems to know about qualifiers, yet typedocs docs state something else?) |
|
Search terms
global, export
Question
So I tried to find a way to document what is essentially a big "mess" around globals.
As a CE author I want to be able to document the usage of my CE without changing the implementation.
Ideally what I would like to do is the following:
Do you see this happening in the future? Or should I rather change the doc tool here?
The text was updated successfully, but these errors were encountered: