Microsoft/TypeScript

Unexpected circular reference error TS7022

Open

#50,200 创建于 2022年8月5日

在 GitHub 查看
 (2 评论) (0 反应) (0 负责人)TypeScript (6,726 fork)batch import
BugDomain: check: Type CircularityHelp Wanted

仓库指标

Star
 (48,455 star)
PR 合并指标
 (平均合并 6天 17小时) (30 天内合并 9 个 PR)

描述

Bug Report

🔎 Search Terms

TS7022

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about TS7022

⏯ Playground Link

💻 Code

/** @template T */
class GenericClass {
	/**
	 * @param {(data: T) => void} handler
	 */
	setHandler(handler) {
	}
}

/** @type {GenericClass<typeof handlers>} */
const theClass = new GenericClass();
theClass.setHandler(() => {});

function emptyFunction() {}

const handlers = {
	thisWorksFine: emptyFunction,
	thisDoesnt: console.log,
};

🙁 Actual behavior

'theClass' is referenced directly or indirectly in its own type annotation, happens only in the JavaScript equivalent of this code and only if an external type is included in the handlers object. Uncommenting thisDoesnt: console.log seems to remove the type errors for some reason. theClass.setHandler(() => {}); also seems to be required for this

🙂 Expected behavior

No error, because there is no error in the TypeScript equivalent either.

贡献者指南