Commit 3b790f61 authored by Robert Knight's avatar Robert Knight

Replace ts-expect-error with `any` cast

This makes it more obvious what is going on. It would be possible to
type this accurately, but I judged the effort not currently worthwhile.
parent ecde7f96
...@@ -3,7 +3,7 @@ import { ListenerCollection } from '../../shared/listener-collection'; ...@@ -3,7 +3,7 @@ import { ListenerCollection } from '../../shared/listener-collection';
/** /**
* Monkey-patch an object to observe calls to a method. * Monkey-patch an object to observe calls to a method.
* *
* The observer is not notified if the method throws. * The `handler` is not invoked if the observed method throws.
* *
* @template {any} T * @template {any} T
* @param {T} object * @param {T} object
...@@ -20,12 +20,13 @@ function observeCalls(object, method, handler) { ...@@ -20,12 +20,13 @@ function observeCalls(object, method, handler) {
throw new Error('Can only intercept functions'); throw new Error('Can only intercept functions');
} }
// @ts-expect-error /** @param {unknown[]} args */
object[method] = (...args) => { const wrapper = (...args) => {
const result = origHandler.call(object, ...args); const result = origHandler.call(object, ...args);
handler(...args); handler(...args);
return result; return result;
}; };
object[method] = /** @type {any} */ (wrapper);
return () => { return () => {
object[method] = origHandler; object[method] = origHandler;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment