Angularjs 变量';Foo';在申报前使用。两类相互依存

Angularjs 变量';Foo';在申报前使用。两类相互依存,angularjs,typescript,tslint,Angularjs,Typescript,Tslint,请帮我解决这个问题 tslint.json中的“声明前不使用”是true。我不允许改变它 问题如下——“在声明“生成错误”之前使用了变量“foo” 代码可简化为: export class One { toSecond() : Two { return new Two(); } } export class Two { toFirst() : One { return new One(); } } 是否可以通过某种方式对其进行黑

请帮我解决这个问题

tslint.json
中的
“声明前不使用”
true
。我不允许改变它

问题如下——“在声明“生成错误”之前使用了变量“foo”

代码可简化为:

export class One {
    toSecond() : Two {
        return new Two();
    }
}

export class Two {
    toFirst() : One {
        return new One();
    }
}

是否可以通过某种方式对其进行黑客攻击,以克服linter警告并获得相同的结果。有什么解决办法吗?

这是以前作为一个文件归档的,解决方案是在声明之前不提升类,不能使用类。在这种情况下,规则是正确的。

您可以执行以下操作:

let Two_forward: typeofTwo;

export class One {
    toSecond() : Two {
        return new Two_forward();
    }
}

export class Two {
    toFirst() : One {
        return new One();
    }
}
// Work around https://github.com/palantir/tslint/issues/3655
type typeofTwo = typeof Two;
Two_forward = Two;

但在我看来,这与仅使用
//tslint:disable next line:no use before declare抑制lint错误相比是不合理的。(如果建议的
strictLocalization
选项成为
strict
的一部分,则可能需要进一步更改)

非常感谢@Matt,TSLint规则标志是目前我的最佳解决方案。