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

How do I properly document the type of functions passed as arguments, without extracting them to another type? #2154

Closed
Annoiiyed opened this issue Jan 29, 2023 · 2 comments
Labels
bug Functionality does not match expectation

Comments

@Annoiiyed
Copy link

Hi! To clarify the title, the following code:

/**
 *
 * Adds equality functions to a data object. This freezes an object.
 * HashCode is lazily evaluated and memoized.
 *
 * @param <D> The type of the data object
 * @param data The data object to add equality to
 * @param equals The equality function
 * @param hashCode The hash code function
 *
 * @returns The data object with equality added
 */
export default function <D extends Record<string, unknown>>(
  data: D,
  equals: (a: D, b: D) => boolean,
  hashCode: (data: D) => number
): D & HasEquals {
    // ....
}

Needs @param hashCode.__type and @param equals.__type, else validation will show the following:

./src/lib/utils/addEquality.ts:20:10 - warning addEquality.equals.__type does not have any documentation.
20      equals: (a: D, b: D) => boolean,

./src/lib/utils/addEquality.ts:21:12 - warning addEquality.hashCode.__type does not have any documentation.
21      hashCode: (data: D) => number

@Annoiiyed Annoiiyed added the question Question about functionality label Jan 29, 2023
@Gerrit0
Copy link
Collaborator

Gerrit0 commented Jan 29, 2023

This looks like a bug in the validation, it should accept the comment on the parameter reflection as the comment.

@Gerrit0 Gerrit0 added bug Functionality does not match expectation and removed question Question about functionality labels Jan 29, 2023
@Gerrit0
Copy link
Collaborator

Gerrit0 commented Feb 26, 2023

Hmm... on second review, I guess it's technically correct that the a parameter of equals isn't documented. I don't think it makes sense to complain about this. You could add an inline comment for this parameter, but I think I'm going to update the validation to ignore parameters within parameters...

export default function <D extends Record<string, unknown>>(
  data: D,
  equals: (/** Inline docs */a: D, b: D) => boolean,
  hashCode: (data: D) => number
): D & HasEquals {
    // ....
}

or

export default function <D extends Record<string, unknown>>(
  data: D,
  /** Inline docs with @param a */
  equals: (a: D, b: D) => boolean,
  hashCode: (data: D) => number
): D & HasEquals {
    // ....
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Functionality does not match expectation
Projects
None yet
Development

No branches or pull requests

2 participants