-
Type:
Bug
-
Resolution: Fixed
-
Priority:
Minor - P4
-
Affects Version/s: None
-
Component/s: None
-
None
-
DevProd Test Infrastructure
-
Fully Compatible
-
ALL
-
Correctness 2026-01-26, Correctness 2026-02-09
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Currently, the type hint for assert.commandWorked returns any:
/**
* Assert that a command worked by testing a result object.
*
* @param {WriteResult | BulkWriteResult | WriteCommandError | WriteError | BulkWriteError} res
* Result that should be successful ("worked").
* @param {string|Function|object} [msg] Failure message, displayed when the assertion fails.
* If a function, it is invoked and its result is used as the failure message.
* If an object, its conversion to json is used as the failure message.
*
* @returns The result object to continue any chaining.
* @throws {Error} if assertion is not satisfied.
*
* @example
* const dbTest = db.getSiblingDB(jsTestName());
* const res = dbTest.createCollection("coll1");
* assert.commandWorked(res);
*/
assert.commandWorked = function (res, msg) {
return _assertCommandWorked(res, msg, {ignoreWriteErrors: false});
};
However, since _assertCommandWorked returns the value it was passed in (on success), we should improve the type hint of assert.commandWorked to reflect that its return type is the same as res, i.e.:
/**
* @template T
*
* @param {T} res
* @returns {T}
*
*/
This Typescript playground link highlights the benefit.