Closed Bug 2065656 Opened 22 days ago Closed 19 days ago

Fix the truncated TabMetricsContext typedef in TabMetrics.sys.mjs

Categories

(Firefox :: Tabbed Browser, task)

task

Tracking

()

RESOLVED FIXED
156 Branch
Tracking Status
firefox156 --- fixed

People

(Reporter: dao, Assigned: dao)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

Filing as a good first bug to learn workflows.

The TabMetricsContext typedef in TabMetrics.sys.mjs documents three properties, but TypeScript only sees the first two. An indented @see sits inside the telemetrySource property description:

 * @property {string} [telemetrySource="unknown"]
 *   The system, surface, or control the user used to take this action.
 *   @see TabMetrics.METRIC_SOURCE for possible values.
 *   Defaults to "unknown".
 * @property {boolean} [isDecomposed=false]

TypeScript's JSDoc parser reads @see as the start of a new block tag and stops collecting @property tags there, so isDecomposed is not part of the type. Note that jsdoc itself is unaffected -- it reports all three properties -- so this is a TypeScript-compatibility fix, not a rendering bug.

The fix is to keep the reference but not as a tag, for example by folding it into the prose:

 * @property {string} [telemetrySource="unknown"]
 *   The system, surface, or control the user used to take this action, one of
 *   the TabMetrics.METRIC_SOURCE values. Defaults to "unknown".

Link to the code:
https://searchfox.org/firefox-main/source/browser/components/tabbrowser/TabMetrics.sys.mjs#84

To verify the fix:

browser/components/tabbrowser is not type-checked in CI yet, so use a scratch project. From the top of your checkout:

mkdir -p artifacts/tm-probe
cat > artifacts/tm-probe/tsconfig.json <<EOF
{
"include": ["../../browser/components/tabbrowser/TabMetrics.sys.mjs"],
"extends": "../../tools/@types/tsconfig.json",
"compilerOptions": {
"checkJs": true, "strict": true, "noImplicitAny": false, "strictNullChecks": false,
"plugins": [{ "transform": "../../tools/ts/plugins/checkRootOnly.js", "transformProgram": true }]
}
}
EOF
./mach node node_modules/typescript/bin/tsc --project artifacts/tm-probe --pretty false

Before the fix that prints:

browser/components/tabbrowser/TabMetrics.sys.mjs(129,5): error TS2353: Object literal may only specify known properties, and 'isDecomposed' does not exist in type 'TabMetricsContext'.

After the fix it prints nothing. (If the command fails because node_modules is missing, run ./mach lint -l eslint browser/components/tabbrowser/TabMetrics.sys.mjs once to populate it.)

Please also run:

./mach lint -l eslint browser/components/tabbrowser/TabMetrics.sys.mjs

Tutorial to contribute:
https://firefox-source-docs.mozilla.org/contributing/contribution_quickref.html
https://firefox-source-docs.mozilla.org/contributing/stack_quickref.html

Please don't ask for the bug to be assigned. It will be automatically assigned to the first patch.

Mentor: dao+bmo
Keywords: good-first-bug
Whiteboard: [lang=js]

TypeScript's JSDoc parser reads the indented @see as the start of a new block tag and stops collecting @property tags there, so isDecomposed was not part of the type. jsdoc itself is unaffected either way, so the rendered documentation does not change.

Assignee: nobody → dao+bmo
Status: NEW → ASSIGNED
Blocks: 2065769
Pushed by dgottwald@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/c70785929336 https://hg.mozilla.org/integration/autoland/rev/d889f28d73af Make the whole TabMetricsContext typedef visible to TypeScript. r=jsudiaman,tabbrowser-reviewers
Status: ASSIGNED → RESOLVED
Closed: 19 days ago
Resolution: --- → FIXED
Target Milestone: --- → 156 Branch
QA Whiteboard: [qa-triage-done-c157/b156]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: