Skip to content

fix(html): preserve ? on optional tuple elements - #796

Open
fibibot wants to merge 2 commits into
denoland:mainfrom
fibibot:fix/html-tuple-optional-element
Open

fix(html): preserve ? on optional tuple elements#796
fibibot wants to merge 2 commits into
denoland:mainfrom
fibibot:fix/html-tuple-optional-element

Conversation

@fibibot

@fibibot fibibot commented Apr 26, 2026

Copy link
Copy Markdown

Summary

Reported in denoland/deno#29669. `render_type_def` in `src/html/types.rs` handled `TsTypeDefKind::Optional` (the kind produced for the trailing-`?` form in tuple element types like `[T, U?]`) by returning the inner type's HTML and dropping the `?`:

```rust
TsTypeDefKind::Optional(inner) => render_type_def(ctx, inner),
```

So this source:

```ts
export function a(x: [number, number?]): number {
return x[0] + (x?.[1] ?? 0);
}
```

rendered as `[number, number]` in HTML even though terminal/JSON output (which goes through `Display` and emits `{ty}?`) was correct. Mirror the `Display` behaviour for HTML.

Test plan

  • Existing snapshot tests `html_test__symbol_group.snap` and the `html_doc_files_multiple` family already exercise an `optionalMethod(): [string?]` symbol; they were silently capturing the buggy output. Snapshots refreshed under `INSTA_UPDATE=always` and now show the `?` (e.g. `[<span class="td-kw">string?]`).
  • Manual repro from the issue: `deno doc --html` on `export function a(x: [number, number?]): number` now renders `[number, number?]` in the parameters table.
  • `cargo fmt --check`, `cargo clippy --tests -- -D warnings`.

`render_type_def` rendered `TsTypeDefKind::Optional` (the kind produced
for the trailing-`?` form in tuple element types like `[T, U?]`) by
returning the inner type's HTML and dropping the `?`. The text-mode
`Display` already emits `{ty}?` — mirror that for HTML so the
generated docs match the source signature.

Snapshots refreshed: `html_test__symbol_group.snap` and the
`html_doc_files_multiple` family now correctly capture the `?`.

Fixes denoland/deno#29669.
@CLAassistant

CLAassistant commented Apr 26, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ crowlKats
❌ fibibot
You have signed the CLA already but the status is still pending? Let us recheck it.

@deno-cla-assistant

Copy link
Copy Markdown

Deno Individual Contributor License Agreement

The following contributors need to sign the CLA before this PR can be merged:

Click here to review and sign the CLA | Re-run CLA check


This is an automated message from CLA Assistant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants