New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected circular reference error TS7022 #50200
Comments
This error occurs in the equivalent TS program: class GenericClass<T> {
setHandler(handler: (date: T) => void) {
}
}
const theClass: GenericClass<typeof handlers> = new GenericClass();
theClass.setHandler(() => {});
function emptyFunction() {}
const handlers = {
thisDoesnt: console.log,
}; Here's a version that doesn't rely on export class GenericClass<T> {
setHandler() {
}
}
declare const theClass: GenericClass<typeof handlers>;
theClass.setHandler()
declare var con: {
new(): unknown;
};
const handlers = {
thisDoesnt: con,
}; |
Here's the circularity. Everything is fine until checking the type of
Here's a variation of the original program where the assertion should actually change the type of export class C<T, U> {
m(t: T, u: U): asserts u is U & { extra: "cool" } {
if ((t as any).extra !== "cool") throw new Error("not cool");
}
}
declare const theClass: C<typeof handlers, { new(): unknown }>;
declare var con: {
new(): unknown;
};
theClass.m({ thisDoesnt: "matter", extra: "cool" });
const handlers = {
thisDoesnt: con,
}; If I could figure out a way for |
Bug Report
π Search Terms
TS7022
π Version & Regression Information
TS7022
β― Playground Link
π» Code
π 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 thehandlers
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.
The text was updated successfully, but these errors were encountered: