-
Notifications
You must be signed in to change notification settings - Fork 664
[api-extractor] Fix an issue where destructured parameters were handled incorrectly #5559
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
base: main
Are you sure you want to change the base?
Conversation
|
Before merging, we can fix the |
|
The synthesised name When there is a single set of destructured parameters, perhaps a more appropriate name would be |
|
Does this patch also fixes the bug related to comments attached to destructured parameters? |
Yes, if you look at the unit test, all comments get stripped during .d.ts emit except for one ( |
|
@ilg-ul After some discussion, we've decided to simplify the naming to I've also updated the implementation to apply to |
|
To be clear, It makes sense that you want "log" to get its own table row, but there are a few challenges:
My goal in this PR was more humble: replace that anonymous subexpression with a name |
|
I will try to repro your missing hyperlink, but is probably an unrelated issue |
If you agree that it makes sense, can we find a solution to make something like this work? If you think that the syntax I used in my code is unfortunate and you have a suggestion for a better, more standard syntax, I am ready to update my code. I also tried a syntax like My personal feeling is that the current implementation (that silently ignores these I understand that for api-extractor usage this might be considered a single parameter, but for api-documenter, as for the function itself, these are separate parameters, and the expectation to use use multiple What can we do? How about the proposal to add |
|
I think TSDoc may have a gap for named sub-properties here; JSDoc handles it: There are, in fact, observable runtime differences between a function that takes a single named parameter and one that destructures the same parameter: most notably the result of |
You mean this one? /**
* Assign the project to an employee.
* @param {Object} employee - The employee who is responsible for the project.
* @param {string} employee.name - The name of the employee.
* @param {string} employee.department - The employee's department.
*/
Project.prototype.assign = function({ name, department }) {
// ...
};In other words, It is fine with me. This would also solve the dilema how to name the anonymous object (options, params, input, etc), since it passes the decision to the user. |

Summary
Consider these functions:
API Extractor will incorrectly report the function parameter name as
{verbose}or[min, max]which can sometimes cause an actual validation error when API Documenter was expecting a normal identifier.Details
Discussed in this Zulip thread:
Comments in destructured parameters trigger errors
In a nutshell, the
{verbose}string is:@paramMy proposed solution is to rewrite the signatures, synthesizing a conventional name for the anonymous parameter:
The
optionsandlistnames are used when there is exactly one destructured parameter. In more general cases (e.g. multiple such parameters), the naming patternanonmyous,anonymous2, ... is used instead.How it was tested
Impacted documentation