【发布时间】:2026-01-07 13:00:01
【问题描述】:
我目前对子函数的类型定义有以下问题。
示例代码:
/** @type {$timeout} */
const $timeout;
// this works with intellisense
const promise = $timeout(() => callback(1234), 999);
// this does not
const wasCanceled = $timeout.cancel(promise);
示例 jsdoc 类型定义:
/**
* @typedef {_timeout} $timeout
*/
/**
* @callback _timeout
*
* @param {function()=} fn A function, whose execution should be delayed.
* @param {number=} [delay=0] Delay in milliseconds.
* @param {boolean=} [invokeApply=true]
* @param {...*=} Pass additional parameters to the executed function.
* @returns {Promise} Promise that will be resolved when the timeout is reached. The promise
* will be resolved with the return value of the `fn` function.
*/
/**
* @callback _timeout#cancel
*
* @description
* Cancels a task associated with the `promise`. As a result of this, the promise will be
* resolved with a rejection.
*
* @param {Promise=} promise Promise returned by the `$timeout` function.
* @returns {boolean} Returns `true` if the task hasn't executed yet and was successfully
* canceled.
*/
我很想正确输入此内容,但我并没有完全弄清楚该怎么做,文档也没有显示任何有用的信息。
这里也没有找到任何东西;)
【问题讨论】:
标签: javascript jsdoc