microsoft / microsoft/TypeScript
JSDOC generics bug for callbacks when args are present
未关闭
还没有人认领这个 Issue。
Bug
Domain: JSDoc
Help Wanted
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
🔎 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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从链接的 TypeScript Playground 复现开始,将 v1 和 v2 的推断类型与预期的 TypeScript 结果进行比较。然后跟踪编译器中 JSDoc 泛型回调的推断路径,并添加一个回归测试,表明当回调有参数时,v1 会被推断为 VC。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, typescript
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100