Open
Description
π Search Terms
"Generics", "JSDOC", "Callback"
π Version & Regression Information
TS 5.7.3
v5.8.0-dev.20250131
β― Playground Link
π» Code
In the following example, define()
should return VC<S>
, but when arg callback
has args it does not resolve S
and returns VC<any>
.
/**
* @template S
* @param {(arg0: { observer: EO }) => S} callback
* @param {Options} [options]
* @returns {VC<S>}
*/
/*
* @type { <S>(fn: (arg0: { observer: EO; }) => S, options?: Options) => VC<S> }
*/
function define(callback, options) {
const { name } = options ?? {}
const observer = new EO()
const state = callback({ observer })
return new VC(state)
}
/**
* @template S
*/
class VC {
/** @type {S} */
state
/**
* @param {S} state
*/
constructor(state) {
this.state = state
}
}
/** @typedef {{ name?: string }} Options */
class EO {}
// Arg `callback` with args - JSDOC doesn't resolve S.
// JSDOC const v1: VC<any>
// TS const v1: VC<boolean>
const v1 = define((arg0) => true, { name: 'default' })
// Arg `callback` without args - JSDOC does resolve S.
// JSDOC const v2: VC<boolean>
// TS const v2: VC<boolean>
const v2 = define(() => true, { name: 'default' })
π Actual behavior
JSDOC doesn't resolve S
π Expected behavior
JSDOC should resolve S in the same way as TS.
Additional information about the issue
No response