TypeScript版本: master
代码
b.d.ts
declare class C {
f: this;
}
declare namespace C {}
export = C;
a.ts
import * as C1 from "./b";
import C2 = require("./b");
function f(t: (c: C1) => void): void {
t(new C2());
}
预期行为:
在 import * as C1
处出现错误。
实际行为:
在导入声明处没有错误。在 new C2()
处出现错误:
src/a.ts(5,7): error TS2345: Argument of type 'C' is not assignable to parameter of type 'C'.
Types of property 'f' are incompatible.
Type 'C' is not assignable to type 'this'.
(可能相关: #20704 )
4条答案
按热度按时间3phpmpom1#
这是因为在
checkTypeRelatedTo
中,冗余的更好的错误检查暂时不适用于逆变失败。请参阅~第9384行。它只检查源代码是否具有起源导入和未混淆的类型 - 为了处理逆变位置,目标也应该被检查。与#20704无关,我认为。vshtjzan2#
为了保持整洁,自动关闭此问题。问题标签表明目前无法采取行动或已经得到解决。
gwbalxhn3#
@weswigham这听起来好像有一个潜在的解决方法?我们应该继续关注这个问题吗?
xxls0lw84#
确实存在一个潜在的修复方法。当前的实现只是没有处理检查用于协变比较的更好的错误。