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

Mark functions that are children of classes or interfaces as methods #2150

Closed
fb55 opened this issue Jan 22, 2023 · 2 comments
Closed

Mark functions that are children of classes or interfaces as methods #2150

fb55 opened this issue Jan 22, 2023 · 2 comments
Labels
enhancement Improved functionality help wanted Contributions are especially encouraged
Milestone

Comments

@fb55
Copy link
Contributor

fb55 commented Jan 22, 2023

Search Terms

documentation structure, functions, methods

Problem

Sometimes functions that become members of classes or interfaces still end up as functions. This doesn't make a difference to users, as they look and feel equivalent. It does however make the generated documentation harder to understand; eg. see https://cheerio.js.org/classes/Cheerio.html

This page has both Functions - Traversing and Methods - Traversing as categories, which makes it harder to understand the page.

Suggested Solution

TypeDoc should normalise the children of classes and interfaces to be exclusively methods. TypeDoc already creates copies of them when creating the signatures, meaning this won't lead to actual functions being turned into methods.

I wrote this plugin today to fix the issue:

const td = require('typedoc');

/** @param {td.Application} app - The app. */
exports.load = function (app) {
  app.converter.on(td.Converter.EVENT_CREATE_DECLARATION, updateFnsToMethods);
};

/**
 * @param {td.Context} context - The context.
 * @param {td.DeclarationReflection} reflection - The reflection.
 */
function updateFnsToMethods(context, reflection) {
  if (
    reflection.kindOf(td.ReflectionKind.Function) &&
    reflection.parent?.kindOf(td.ReflectionKind.ClassOrInterface)
  ) {
    // Unset the `Function` flag, set the `Method` flag.
    reflection.kind ^= td.ReflectionKind.Function;
    reflection.kind |= td.ReflectionKind.Method;
  }
}

My suggestion is to include the relevant logic in TypeDoc, as I can't think of a case where this isn't wanted.

@fb55 fb55 added the enhancement Improved functionality label Jan 22, 2023
@Gerrit0
Copy link
Collaborator

Gerrit0 commented Jan 28, 2023

That's... an interesting way of structuring an interface. Seems like a reasonable request. Will require adjustments to the comment discovery method so that methods catch comments that "normally" end up on functions.

@Gerrit0 Gerrit0 added the help wanted Contributions are especially encouraged label Jan 28, 2023
@Gerrit0
Copy link
Collaborator

Gerrit0 commented Mar 25, 2023

Well, that was confusing. Apparently this only happens if you are using export const x = () => {} -- regular function declarations are already handled as methods!

@Gerrit0 Gerrit0 added this to the v0.24 milestone Mar 25, 2023
@Gerrit0 Gerrit0 mentioned this issue Mar 25, 2023
8 tasks
@Gerrit0 Gerrit0 closed this as completed in a41ac2d Apr 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improved functionality help wanted Contributions are especially encouraged
Projects
None yet
Development

No branches or pull requests

2 participants