Microsoft/TypeScript
Voir sur GitHubJSDOC generics bug for callbacks when args are present
Open
#61 090 ouverte le 31 janv. 2025
BugDomain: JSDocHelp Wanted
Métriques du dépôt
- Stars
- (48 455 stars)
- Métriques de merge PR
- (Merge moyen 6j 17h) (9 PRs mergées en 30 j)
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