-
Notifications
You must be signed in to change notification settings - Fork 697
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
react forwardRef shows up as namespace *and* function. #2461
Comments
for what it's worth, I was able to subvert this by forcing the type on export with an 'as' . I think I understand why it happens: React's additional properties like displayName, propTypes, defaultProps, etc, makes a function into an object, and thus a namespace according to typedoc. things like React.memo and React.forwardRef explicitly export that object-function instead of a simple component-shaped-function that one usually exports. would this classify as a "working as intended" or is there a more elegant way to handle this particular react side-effect? |
It does count as working as intended right now, though looking back at #2436, I'm not entirely sure why I decided to make a namespace in this case rather than putting the property declarations on the function. Consistency is nice, but in this case, and the Object.assign case from that issue, I think it makes more sense to treat these as function properties than creating a separate namespace. |
Would function properties appear in the index, then? I ask because I'm working on a project where certain functions have properties and methods; e.g. there is an Slightly more complex: I have a callable Playing around with the fix for #2436, it looks like directing the |
What do you mean by "in the index"? The change that you made is what I was considering, with a few other adjustments to handle some more edge cases. This results in both properties being shown in the "On this page" section, and the "index", but not under the full site navigation tree as functions are not expanded. This makes me want to add more options for configuring the navigation tree... The const is a totally different issue -- and a way worse one. Overloads are awful, overloads without overload syntax (e.g. variables rather than multiple function declarations) are even worse. There is only one declaration, so unless you repeat the type, there's only one place to add the comment, so TypeDoc applies it to all signatures. const x: {
/** Docs for signature 1 */
(): string;
/** Docs for signature 2 */
(x: number): number;
} = ... In this case, since you're just adding a category, we're in luck, as the inline form of export interface Int {
/** Docs for string returning signature */
(): string;
/** Docs for number returning signature */
(x: string): number;
}
/**
* {@inheritDoc Int}
* @category Foo
*/
export const foo: Int = () => {
throw 1;
}; |
By "in the index" I meant that on the main index (modules.html) there would be entries for the In practice the issue has largely been mooted for me at this point; I gave up on getting Typedoc to match the project and instead made the project match Typedoc, i.e. I got rid of the namespaces/function "methods". (Of course, after doing that, I ended up spending enough time hacking on the Typedoc default theme figuring out how to get the markdown pages plugin working with the new navigation system, that if I really needed to I'm pretty sure I could make the navigation work whatever way I wanted now, but I like the namespace-free version of my API better so I'm probably not going back. 😁) |
Ah, that index doesn't include anything nested. I tend to also prefer namespace-free APIs |
Search terms
react forwardref namespace function kind
Expected Behavior
exporting a forwardRef component should show up once in the generated docs, as a function, consistent with any other functional component.
Actual Behavior
typedoc has any forwardRef component showing up as both a namespace and a function
Steps to reproduce the bug
Environment
The text was updated successfully, but these errors were encountered: